【问题标题】:only change font size (and not font name)只改变字体大小(而不是字体名称)
【发布时间】:2013-10-04 21:49:31
【问题描述】:

我想做的是改变字体大小。

我知道下面的语句会改变字体大小,但它会改变字体名称,因为我们使用的是systemFontOfSize

[UIFont systemFontOfSize: 13.0];

我知道备用选项如下所述。

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

但我不想使用 fontWithName,因为我在 IB 中设置它。

我不想使用字体名称,因为我的应用程序是多语言的,因此我不想使用字体名称。

知道如何只更改字体大小而不更改字体名称。

【问题讨论】:

    标签: objective-c fonts uifont system-font


    【解决方案1】:

    UIFont 的字体度量属性是只读的,太糟糕了。如果可以动态调整它们而不必在下面执行此操作,那就太好了:

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

    【讨论】:

    • ohhh... 意味着再次阅读并使用该字体... :D :p 丑陋,但我认为这是最后的选择
    • 对...最好的解决办法是让 Apple 允许 ".pointSize" property 为“readwrite”。您应该通过bugreporter.apple.com 向 Apple 提交有关此功能的请求。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-23
    • 2019-11-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多