Set custom font

北城余情 提交于 2020-01-15 11:01:03

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!