问题
Here is how I set custom font in my app
[self.titleLabel setFont:[UIFont fontWithName:@"FontName" size:self.font.pointSize]];
I get font is deprecated.
How to fix this ?
//EDIT
UIButtonCustom.h
#import <Foundation/Foundation.h>
@interface UIButtonCustom : UIButton
@end
UIButtonCustom.m
-(void)awakeFromNib
{
[super awakeFromNib];
[self.titleLabel setFont:[UIFont fontWithName:@"FontName" size:self.font.pointSize]];
}
回答1:
Since you did not say what type of class self
is I am not exactly sure why you got the deprecated message. Generally when ever you get a message about something being deprecated refer to the documentation, if it is 3rd party (not Apple's or your code) refer to the 3rd party docs. Determine what class font belongs to in self's hierarchy then check the documentation. The docs will almost always offer the new preferred way to accomplish the same thing.
Update:
As I stated above, refer to UIButton's documentation and you will find :
The font used to display text on the button. (Deprecated in iOS 3.0. Use the font property of the titleLabel instead.)
回答2:
You can fix it like this.
[self.titleLabel setFont:[UIFont fontWithName:@"FontName" size:self.titleLabel.font.pointSize]];
来源:https://stackoverflow.com/questions/9744061/set-custom-font