Skip to content

Instantly share code, notes, and snippets.

@pec1985
Created June 7, 2011 17:12
Show Gist options
  • Save pec1985/1012669 to your computer and use it in GitHub Desktop.
Save pec1985/1012669 to your computer and use it in GitHub Desktop.
Custom Table View
var win = Ti.UI.createWindow({
backgroundColor:'white'
});
function myRow(e){
e = e || {};
e.height = e.height || 44;
e.left = 0;
e.right = 0;
e.borderWidth = 1;
e.borderColor = '#ccc';
e.backgroundColor = e.backgroundColor || 'white';
var view = Ti.UI.createView(e);
var label = Ti.UI.createLabel({
text:e.text,
font:{
fontSize:20,
fontWeight:'bold'
},
left:20,
right:20,
top:10,
bottom:10
});
if(e.leftImage){
label.left = 100;
view.add(
Ti.UI.createImageView({
image:e.leftImage,
left:5,
width:90,
height:90
})
);
view.height = 100;
}
if(e.rightImage){
label.right = 100;
view.add(
Ti.UI.createImageView({
image:e.rightImage,
right:5,
width:90,
height:90
})
);
view.height = 100;
}
view.add(label);
return view;
}
function myTable(){
var view = Ti.UI.createScrollView({
layout:'vertical',
contentHeight:'auto',
top:0,
bottom:0,
right:0,
left:0
});
return view;
}
var table = myTable();
for (var i=0; i < 100; i++) {
table.add(
myRow({
text:'Hello #'+i,
leftImage:'https://secure.gravatar.com/avatar/451ff3132cec742cab2d84f7232c908e?s=140&d=https://d3nwyuy0nl342s.cloudfront.net%2Fimages%2Fgravatars%2Fgravatar-140.png'
})
);
};
win.add(table);
win.open();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment