Titanium Community Questions & Answer Archive

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

How do you resize a label's font in an eventHandler?

I'm doing this currently and setting the font in the addEventListener is not working, the font resizes down to the device default, which I assume means I'm not doing it right. Any ideas?

var w = Ti.UI.createWindow({backgroundColor:'#fff'});

var b = Ti.UI.createButton({
title:'Click Me',
top:10,
height:40,
width:200
});

var lab = Ti.UI.createLabel({
text: 'test',
top: 150,
height: 140,
width: 300,
font:{fontSize:20},
color: '#c00',
backgroundColor: '#ccc'
});

w.add(b);
w.add(lab);

b.addEventListener('click', function()
{
lab.font = '{fontSize:100}';
});

w.open();

— asked August 28th 2010 by Stephen Babigian
  • font
  • iphone
  • label
  • resize
  • scale
3 Comments
  • And instead of this: lab.font = '{fontSize:100}';

    I also just tried setting the font size this way instead and still no luck:

    lab.font.fontSize = 100;

    Thinking it might be a bug. Can anyone confirm?

    — commented August 28th 2010 by Stephen Babigian
  • Confirmed. I've tried pretty much every way of changing the font size outside of the actual var and it never works, it always switches back to the default font size of the device.

    /Request fix for 1.5.0?

    — commented August 28th 2010 by Colton Arabsky
  • Entered ticket:

    https://appcelerator.lighthouseapp.com/projects/32238/tickets/1667-changing-label-views-fontfontsize-property-after-view-is-rendered-has-no-effect

    — commented August 29th 2010 by Stephen Babigian

1 Answer

  • Nolan updated the ticket and let me know that the correct way to update the fontSize property is like so:

    label.font = {fontSize:70};

    I was mistakenly using single quotes around my object. Guess it was a long day.

    — answered August 28th 2010 by Stephen Babigian
    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.