I get a warning saying that setFont is deprecated?
[button setFont:[UIFont boldSystemFontOfSize:13]];
Any suggestions how to take it away pls..
As UIButton exposes its titleLabel starting from iPhone OS 3.0 you must set font to it directly:
[button.titleLabel setFont:[UIFont boldSystemFontOfSize: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
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]];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With