简体   繁体   English

仅更改字体大小(而不更改字体名称)

[英]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 我知道下面的语句会更改字体大小,但是它会更改字体名称,因为我们使用的是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. 但是我不想使用fontWithName,因为我在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. 太糟糕了,UIFont的字体指标属性是只读的。 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 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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