0

What I want to do is change the font size.

I know below statement will change the font size, but it changes the font name because we are using systemFontOfSize

[UIFont systemFontOfSize: 13.0];

I know alternate option is as mentioned below.

[myLabel setFont:[UIFont fontWithName:@"Helvetica-Bold" size:13.0]];

but I don't want to use fontWithName as I am setting that in IB.

I don't want to play with font name as my app is multi-language and hence I don't want to play with font name.

Any idea how can I just change fontsize and don't change the fontname.

Fahim Parkar
  • 30,974
  • 45
  • 160
  • 276

1 Answers1

3

Too bad that the font metrics properties of UIFont are readonly. It'd be nice if they could be adjusted dynamically without having to do this below:

UIFont * fontFromLabel = myLabel.font;

// now we have the font from the label, let's make a new font
// with the same font name but a different size
if(fontFromLabel)
{
    // 13, or whatever size you want
    UIFont * newFontForLabel = [UIFont fontWithName: fontFromLabel.fontName size: 13.0f]; 
    if(newFontForLabel)
    {
        [myLabel setFont: newFontForLabel];
    }
}
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • ohhh... means read and use that font again... :D :p ugly but I think this is last option – Fahim Parkar Sep 28 '13 at 19:45
  • 1
    right... the best fix would be for Apple to allow the [`".pointSize`" property](https://developer.apple.com/library/ios/documentation/uikit/reference/UIFont_Class/Reference/Reference.html#//apple_ref/occ/instp/UIFont/pointSize) to be "`readwrite`". You should file a feature request with Apple at http://bugreporter.apple.com about this. – Michael Dautermann Sep 28 '13 at 19:48