1

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]]; } 
2
  • titlelabel is kind of UILabel class? Commented Mar 16, 2012 at 20:35
  • 1
    The UILabel's font property is not deprecated so it is safe to assume OP is inheriting from a class where font is deprecated. Commented Mar 16, 2012 at 20:37

2 Answers 2

5

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.)

Sign up to request clarification or add additional context in comments.

1 Comment

The answer is correct, the deprecation message you're seeing is because you're still referring to self.font in your fontWithName:size: call.
4

You can fix it like this.

[self.titleLabel setFont:[UIFont fontWithName:@"FontName" size:self.titleLabel.font.pointSize]]; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.