Skip to content

Instantly share code, notes, and snippets.

@iantearle iantearle/app.js forked from pec1985/app.js
Created Jan 4, 2012

Embed
What would you like to do?
SmartLabel
var UI = {};
var W = {};
var V = {};
var AUTODETECT_NONE = Ti.UI.iOS.AUTODETECT_NONE;
var AUTODETECT_ALL = Ti.UI.iOS.AUTODETECT_ALL;
var AUTODETECT_PHONE = Ti.UI.iOS.AUTODETECT_PHONE;
var AUTODETECT_LINK = Ti.UI.iOS.AUTODETECT_LINK;
var AUTODETECT_ADDRESS = Ti.UI.iOS.AUTODETECT_ADDRESS;
var AUTODETECT_CALENDAR = Ti.UI.iOS.AUTODETECT_CALENDAR;
UI.SmartLabel = function(a){
a = a || {}
a.enabled = false,
a.autoLink = a.autoLink || AUTODETECT_ALL;
a.font = a.font || {fontSize:16};
a.value = a.value || a.text || '';
a.text = a.value;
if(a.height == 'auto'){
var h = Ti.UI.createLabel(a).toImage().height+(a.font.fontSize*2);
a.height = h;
h = null;
delete a.text;
}
a.scrollable = false;
return Ti.UI.createTextArea(a);
};
UI.View = function(a){
a = a || {}
return Ti.UI.createView(a);
};
UI.Win = function(a){
a = a || {}
return Ti.UI.createWindow(a);
};
UI.Table = function(a){
a = a || {};
if(a.grouped){
a.style = Ti.UI.iPhone.TableViewStyle.GROUPED;
delete a.grouped
};
return Ti.UI.createTableView(a);
};
UI.Row = function(a){
a = a || {};
return Ti.UI.createTableViewRow(a);
}
W.SampleWindow = function(){
var win = UI.Win({
backgroundColor:'#ccc'
});
var label = UI.SmartLabel({
text:'Hello World \nPhone Number 555-123-4567 \nEmail: developer@company.com \nSite: http://appcelerator.com \nEvent: Jan 25, 2012 \n\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ac viverra nisi. Mauris suscipit porta nulla ut scelerisque. Pellentesque tempor metus elementum urna adipiscing lobortis.',
autoLink: AUTODETECT_ALL
});
win.add(label);
return win;
}
W.MainWindow = function(){
var win = UI.Win({
backgroundColor:'#111'
});
var table = UI.Table({
separatorStyle:Titanium.UI.iPhone.TableViewSeparatorStyle.NONE,
grouped:true,
scrollable:false
});
var scrollView = Ti.UI.createScrollView({
top:0,bottom:0,right:0,left:0,
contentHeight:win.size.height+1,
contentWidth:'auto'
});
var text = UI.SmartLabel({
text:'Hello World \nPhone Number 555-123-4567 \nEmail: developer@company.com \nSite: http://appcelerator.com \nEvent: Jan 25, 2012 \n\nLorem ipsum dolor sit amet, consectetur adipiscing elit. Maecenas ac viverra nisi. Mauris suscipit porta nulla ut scelerisque. Pellentesque tempor metus elementum urna adipiscing lobortis.',
autoLink: AUTODETECT_ALL,
top:100,
bottom:-1
});
scrollView.add(text);
win.add(table);
win.add(scrollView);
this.addSubview = win.add;
this.open = win.open;
}
var win = new W.MainWindow();
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.