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.

有帮助吗?

解决方案

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];
    }
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top