Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

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?

— asked November 13th 2011 by Henrik Thomsen
  • tableview
  • tableviewheader
  • tableviewrow
0 Comments

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

    — answered November 13th 2011 by Aaron Saunders
    permalink
    2 Comments
    • And I have tried that. But still I cant change the style of the header. I found another example with sections. And that did not work either. So I am wondering if it is possible to do this.
      Could you provide me with an example?
      I want a bigger font than the default.

      — commented November 13th 2011 by Henrik Thomsen
    • can you post the code where you have tried? Would be easier than me writing something up

      — commented November 13th 2011 by Aaron Saunders
  • 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??

    — answered November 13th 2011 by Henrik Thomsen
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.