Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

setFont Deprecated?

I get a warning saying that setFont is deprecated?

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

Any suggestions how to take it away pls..

like image 663
SJ Reddy Avatar asked Nov 17 '10 16:11

SJ Reddy


3 Answers

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

[button.titleLabel setFont:[UIFont boldSystemFontOfSize:13]];
like image 140
Vladimir Avatar answered Nov 16 '22 08:11

Vladimir


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

like image 11
ceejayoz Avatar answered Nov 16 '22 10:11

ceejayoz


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]];
like image 11
lekksi Avatar answered Nov 16 '22 08:11

lekksi