Creating Labels using Titanium

deepak - Mon Jan 30 2012 22:38:34 GMT-0500 (EST)

Label Reference in Titanium API

Label Reference in Titanium API

deepak - Mon Jan 30 2012 22:39:07 GMT-0500 (EST)

Sample code


/**
 * Creating a label
 */
var label1 = Titanium.UI.createLabel({
   color:'#321222',
   text:'I am Window 1',
   font:{fontSize:20,fontFamily:'Helvetica Neue'},
   width:'10',
   backgroundImage:'page_title_bar_bg.png'
});

deepak - Mon Jan 30 2012 22:49:11 GMT-0500 (EST)

Sample to make 100% width


var label1 = Titanium.UI.createLabel({
   color:'#FFFFFF',
   text:'I am Window 1',
   font:{fontSize:20,fontFamily:'Helvetica Neue'},
   width:'100%',
   textAlign:'center',
    height: 30.0,
    top: 5.0, 
   backgroundImage:'page_title_bar_bg.png'
});

deepak - Sun Mar 25 2012 13:06:17 GMT-0400 (EDT)

Sample Output

deepak - Sun Mar 25 2012 13:09:25 GMT-0400 (EDT)

Whole code for the above screenshot


// this sets the background color of the master UIView 
(when there are no windows/tab groups on it)
Titanium.UI.setBackgroundImage('background_splash.png');

// create tab group
var tabGroup = Titanium.UI.createTabGroup();


//
// create base UI tab and root window
//
var win1 = Titanium.UI.createWindow({  
    title:'Tab 1',
    backgroundImage:'\background_splash.png'
    
});

/**
 * Creates the tab
 */
var tab1 = Titanium.UI.createTab({  
    icon:'KS_nav_views.png',
    title:'Tab 1',
    window:win1
});


var view1 = Titanium.UI.createView({
   borderRadius:10,
   width:'100%',
   height:30,
   top: 5,
   backgroundImage:'page_title_bar_bg.png'
});


/**
 * Creating a label
 */
var label1 = Titanium.UI.createLabel({
   color:'#FFFFFF',
   text:'I am Window 1',
   font:{fontSize:20,fontFamily:'Helvetica Neue'},
   textAlign:'center',
   
});


view1.add(label1);


/**
 * Adding the label to the window
 */
win1.add(view1);


// create controls tab and root window
//
var win2 = Titanium.UI.createWindow({  
    title:'Tab 2',
    backgroundColor:'#fff'
});
var tab2 = Titanium.UI.createTab({  
    icon:'KS_nav_ui.png',
    title:'Tab 2',
    window:win2
});

var label2 = Titanium.UI.createLabel({
   color:'#999',
   text:'I am Window 2',
   font:{fontSize:20,fontFamily:'Helvetica Neue'},
   textAlign:'center',
   width:'auto'
});

win2.add(label2);

//  add tabs
tabGroup.addTab(tab1);  
tabGroup.addTab(tab2);  

// open tab group
tabGroup.open();