Created
February 28, 2012 03:55
-
-
Save pec1985/1929288 to your computer and use it in GitHub Desktop.
Titanium Vertical Label
This file contains 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
// use this as a normal Ti.UI.Label | |
function VerticalLabel(_params){ | |
// store the text in this variable | |
var text = _params.text || ''; | |
// create an array of letters | |
var array = text.split(''); | |
// get the length of the array (letters) | |
var len = array.length; | |
// delete the text parameters, not needed in views | |
delete _params.text; | |
// get the font, if any | |
_params.font = _params.font || {fontSize:16}; | |
// get the height of the font, for the height of the labels and view | |
var height = _params.font.fontSize || 16; | |
// ensure that these params exist, otherwise create them | |
_params.width = _params.width || 10; | |
_params.height = _params.height || len * height; | |
_params.textAlign = _params.textAlign || 'center'; | |
_params.layout = 'vertical', | |
// create the view with the parameters needed | |
var view = Ti.UI.createView(_params); | |
// delete all that we don't need | |
delete _params.layout; | |
delete _params.backgroundColor; | |
delete _params.left; | |
delete _params.right; | |
delete _params.top; | |
delete _params.bottom; | |
// reset the height with the height variable | |
_params.height = height; | |
// loop and create the labels | |
for(var i = 0; i < len; i++){ | |
// create the text for the labels, one by one | |
_params.text = array[i]; | |
// create the label | |
var label = Ti.UI.createLabel(_params); | |
// add the label to the view | |
view.add(label); | |
} | |
// return the view | |
return view; | |
} | |
var win = Ti.UI.createWindow({backgroundColor:'ccc'}); | |
// create the vertical label | |
var label = VerticalLabel({ | |
width:15, | |
left:20, | |
text:'Titanium Rocks!', | |
backgroundColor:'pink', | |
font:{fontSize:16, fontWeight:'bold'} | |
}) | |
// add it to the window | |
win.add(label); | |
win.open(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment