setFont Deprecated?

前端 未结 3 960
无人及你
无人及你 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]];
    

提交回复
热议问题