Created
September 1, 2011 19:39
-
-
Save tonylukasavage/1187066 to your computer and use it in GitHub Desktop.
cross-platform labels with padding in tableviewrow
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var isAndroidValue = undefined; | |
function isAndroid() { | |
if (isAndroidValue === undefined) { | |
isAndroidValue = Ti.Platform.osname; | |
} | |
return isAndroidValue; | |
} | |
// The trick here is that `left` and `right` would constantly give me the wrong height and truncate the Label text | |
// when using padded Labels in a TableViewRow on Android. They work fine on iOS though. To get around this I just use | |
// an estimated percentage value for `width` that would closely mimic the `left` and `right` values I'd use on iOS. | |
// Also note that I set `left` and `right` AFTER the Label creation. Despite the fact that the docs say the default | |
// value for `left` and 'right` is 'auto', I get weird behavior if I set them to 'auto' for Android. | |
// | |
// The result `label` here should be a non-truncating, padded label that you can put in a TableViewRow. | |
var label = Ti.UI.createLabel({ | |
text: 'Some text... you usually need a lot of text here for the padding issue arise, so fill this in as necessary', | |
textAlign:'left', | |
backgroundColor:'#fff', | |
color:'#000', | |
height:'auto', | |
width: isAndroid() ? '92%' : 'auto', | |
top: 10, | |
bottom: 10, | |
font: { | |
fontSize:16 | |
} | |
}); | |
if (!isAndroid()) { | |
bio.right = 10; | |
bio.left = 10; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment