Search code examples
appceleratorappcelerator-mobileappcelerator-alloy

How can set programmatically style to Label in appcelerator


I want to set programmatically the font style to Label in one appcelerator application.

So this is:

socialHistory.tss

".headerTableLabel" : {
    top : "10px",
    color : "#B3B3B3",
    textAlign : "center",
    width: '340px',
    font : {
        fontSize : "20pt",
        fontWeight : "Italic"
    }
}

This is my socialHistory.js

function createHeader(headerText){
   var heading = Ti.UI.createView({
      height:30, top : 15,
      backgroundColor : "#0c7b84"
   });

   var headingText = Ti.UI.createLabel({
       text : headerText,
       classes: 'headerTableLabel'
   });

      heading.add(headingText);

      return heading;
}

I want to set programmatically the style of my Label under createLabel method. But it not works.


Solution

  • Try it like this:

    function createHeader(headerText){
       var heading = Ti.UI.createView({
          height:30, top : 15,
          backgroundColor : "#0c7b84"
       });
    
       var headingText = $.UI.create("Label", {
           classes: 'headerTableLabel'
       );
       headingText.text = headerText;
    
          heading.add(headingText);
    
          return heading;
    }