Label function with variable font-size

You must Login before you can answer or comment on any questions.

I have the following function which I use to create a label and return a view. It works great with one exception. I'm unable to get a variable font size using logic. Any ideas how I can set this?

Thanks.

posterLabels = function(type, text) {
      var fontsize = type === 'heading' ? 40 : 16;
      var label = Titanium.UI.createLabel({
            text: text,
            height: 'auto',
            width: 'auto',
            color: '#FFF',
            font: { fontSize: fontsize },
            textAlign: 'center'
          });
      return Titanium.UI.createView().add(label);
    };

3 Answers

wow...i'm a noob. I never had it setup to pass in 'heading' I had it passing 'header'. D'oh!

What happens if you replace the === with == instead? Personally, I always enclose the test in parentheses, like:

var fontsize = ( type == 'heading' ) ? 40: 16;

Try that and see what happens.

Yeah i did all that. I tested the code in Chrome's console and it returns the correct value. For whatever reason fontSize doesn't like the variable.

Your Answer

Think you can help? Login to answer this question!