简体   繁体   中英

only change font size (and not font name)

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];
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM