Change style on tableview Header
I have seen a lot of examples on this issue, but it is not quite what I am looking for. Or I cant get it to work.
I have a tableview where I am adding rows like this:
var data = [
{title:'Name / Adress', hasChild:true, header:'User Info'},
{title:'Contact info', hasChild:true},
{title:'New Messages', hasChild:true, header:'Messages'},
{title:'Old Messages', hasChild:true},
];
But I cant change the header style. I want to change the background and font size. But how?
2 Answers
-
You will need to use the
headerView
object on the tableView to customize the look of the header.http://developer.appcelerator.com/apidoc/mobile/1.7.1/Titanium.UI.TableView-object
-
Of course :-)
var createCustomView = function(title) { var view = Ti.UI.createView({ backgroundColor: '#222', height: 40 }); var text = Ti.UI.createLabel({ text: title, left: 20, color: '#fff' }); view.add(text); return view; }; // create table view data object var section1 = Ti.UI.createTableViewSection({ headerView: createCustomView('User info'), }); var section2 = Ti.UI.createTableViewSection({ headerTitle: 'Messages' }); var section3 = Ti.UI.createTableViewSection({ headerTitle: 'Forum' }); section1.add(Ti.UI.createTableViewRow({ title:'Name', hasChild:true })); section1.add(Ti.UI.createTableViewRow({ title:'Contact info', hasChild:true })); section2.add(Ti.UI.createTableViewRow({ title:'Nye beskeder', hasChild:true })); section3.add(Ti.UI.createTableViewRow({ title:'Forum', hasChild:true })); // Now, here's our table, and we're setting the data to hold the sections var tableview = Ti.UI.createTableView({ data:[section1,section2,section3] });
But when I add the headerview:createCustomView('User info') It disapears??