Skip to content

Instantly share code, notes, and snippets.

@pec1985
Created February 28, 2012 03:55
Show Gist options
  • Select an option

  • Save pec1985/1929288 to your computer and use it in GitHub Desktop.

Select an option

Save pec1985/1929288 to your computer and use it in GitHub Desktop.

Revisions

  1. pec1985 revised this gist Feb 28, 2012. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions app.js
    Original file line number Diff line number Diff line change
    @@ -58,9 +58,9 @@ var win = Ti.UI.createWindow({backgroundColor:'ccc'});
    var label = VerticalLabel({
    width:15,
    left:20,
    text:'Rick, you\'re fired!',
    text:'Titanium Rocks!',
    backgroundColor:'pink',
    font:{fontSize:20, fontWeight:'bold'}
    font:{fontSize:16, fontWeight:'bold'}
    })

    // add it to the window
  2. pec1985 created this gist Feb 28, 2012.
    68 changes: 68 additions & 0 deletions app.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,68 @@
    // 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:'Rick, you\'re fired!',
    backgroundColor:'pink',
    font:{fontSize:20, fontWeight:'bold'}
    })

    // add it to the window
    win.add(label);
    win.open();