Skip to content

Instantly share code, notes, and snippets.

@FokkeZB
Last active January 16, 2023 09:35
Show Gist options
  • Star 20 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save FokkeZB/5084675 to your computer and use it in GitHub Desktop.
Save FokkeZB/5084675 to your computer and use it in GitHub Desktop.
Who said you can't do padding in Titanium (Alloy)?
"#wrapper": {
// Set wrapper to adjust it's size to it's contents
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
// Set stuff like borders and backgrounds on the wrapper
backgroundColor: "red"
}
"#content": {
// Set content to anything but the default Ti.UI.FILL
// For example a absolute (dp) or relative (%) value
// Or again, set to adjust to it's content (the text)
width: Ti.UI.SIZE,
height: Ti.UI.SIZE,
// Set the padding values like so:
top: "10dp", right: "10dp", bottom: "10dp", left: "10dp",
// Set stuff like color and font on the content
color: "white"
}
<Alloy>
<Window>
<!-- Wrap the element you need padding for in another view -->
<View id="wrapper">
<Label id="content">Hello, World</Label>
</View>
</Window>
</Alloy>
Copy link

ghost commented Sep 22, 2013

You're the best!!

@antoniputra
Copy link

that is very awesome !!

@andresmafra
Copy link

awesome!

@schoettler
Copy link

That is... Margin of the child. If i'd like something like a padding into a TextField for the inner text?

@bali001
Copy link

bali001 commented Jun 17, 2015

ahh, thanks :)

@FokkeZB
Copy link
Author

FokkeZB commented Jan 13, 2016

@schoettler for iOS only we have paddingLeft and paddingRight for the TextField. For Android you could use a custom theme.

@lolo912
Copy link

lolo912 commented Jan 9, 2019

Thank you a lot, i was starting to get very hangry cause i was not able to understand how positioning works with appcelerator, thanks to your code i understood the difference between Ti.UI.SIZE and Ti.UI.FILL which have terrible behavior.

I'm now able to center a button in a view like i want, to "crack" padding !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment