【问题标题】:How can I change the font size of a uilabel without changing the font itself?如何在不更改字体本身的情况下更改 uilabel 的字体大小?
【发布时间】:2013-05-14 13:10:57
【问题描述】:

我遇到了一个问题,我允许用户为我的项目中的标签选择字体,但是当用户设置该标签的大小(使用不同的按钮)时,标签会重置为默认字体.我希望能够保留用户应用的字体,同时仍然允许用户更改字体大小。任何帮助表示赞赏,谢谢!

这是我的代码..

-(IBAction)setFont{

    [userText setFont:[UIFont fontWithName:@"Arial-BoldMT" size:50.0]];

//I had to add a size when setting the font or else I got an error


}



-(IBAction)setFontSize{

  [userText setFont:[UIFont systemFontOfSize:24]];

}

【问题讨论】:

    标签: objective-c fonts uilabel font-size


    【解决方案1】:

    只需对标签的当前字体使用fontWithSize: 方法即可:

    - (IBAction)setFontSize {
        // Keep the same font but change its size to 24 points.
        UIFont *font = userText.font;
        userText.font = [font fontWithSize:24];
    }
    

    【讨论】:

      【解决方案2】:

      函数[UIFont systemFontOfSize:] 将始终返回默认系统字体。您可以使用在 setFont 中调用的相同函数,即[UIFont fontWithName:size:]

      【讨论】:

        猜你喜欢
        • 2015-09-14
        • 2016-11-22
        • 2012-06-16
        • 2014-10-07
        • 2020-01-04
        • 2021-07-18
        • 2014-08-09
        • 1970-01-01
        • 2011-02-24
        相关资源
        最近更新 更多