only change font size (and not font name)

旧城冷巷雨未停 提交于 2019-12-08 13:05:45

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/19070385/only-change-font-size-and-not-font-name

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!