setFont Deprecated?

前端 未结 3 952
无人及你
无人及你 2020-12-14 00:28

I get a warning saying that setFont is deprecated?

[button setFont:[UIFont boldSystemFontOfSize:13]];

Any suggestions how to take it away p

相关标签:
3条回答
  • 2020-12-14 01:04

    The accepted answer works and sets the font for one button instance. In case you want to set application wide font for all UIButtons, you can do it like this:

    // Set font to be used for labels inside UIButtons
    [[UILabel appearanceWhenContainedIn:[UIButton class], nil] setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:15.0]];
    

    This was not specifically asked in the question, but in case you need to set the font for all labels (not inside UIButtons), you can do it like this:

    // Set font for all UILabels
    [[UILabel appearance] setFont:[UIFont fontWithName:@"HelveticaNeue" size:13.0]];
    
    0 讨论(0)
  • 2020-12-14 01:13

    As UIButton exposes its titleLabel starting from iPhone OS 3.0 you must set font to it directly:

    [button.titleLabel setFont:[UIFont boldSystemFontOfSize:13]];
    
    0 讨论(0)
  • 2020-12-14 01:13

    Setting the font of the button directly is depracated in 3.x versions of the SDK. Instead, you need to set the properties of the button's titleLabel property.

    Code: (mybutton).titleLabel.font = [UIFont systemFontOfSize:13];

    Source: http://www.iphonedevsdk.com/forum/iphone-sdk-development/26126-warning-setting-font-button.html

    0 讨论(0)
提交回复
热议问题