仅更改字体大小(而不更改字体名称) [英] only change font size (and not font name)

查看:135
本文介绍了仅更改字体大小(而不更改字体名称)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要做的是更改字体大小.

What I want to do is change the font size.

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

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

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

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.

推荐答案

可惜UIFont的字体指标属性为只读.如果可以在不执行以下操作的情况下对其进行动态调整,那就太好了

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

这篇关于仅更改字体大小(而不更改字体名称)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆