Created
April 2, 2015 19:58
-
-
Save softmaxsg/8a3ce30331f9f07f023e to your computer and use it in GitHub Desktop.
UILabel with automatic overriding font property with specific font face
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import <UIKit/UIKit.h> | |
@interface UILabelEx : UILabel | |
@property (nonatomic) NSString *overrideFontName; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "UILabelEx.h" | |
@implementation UILabelEx | |
- (void)setOverrideFontName:(NSString *)overrideFontName | |
{ | |
if (![_overrideFontName isEqualToString:overrideFontName]) | |
{ | |
_overrideFontName = overrideFontName; | |
self.font = self.font; | |
} | |
} | |
- (void)setFont:(UIFont *)font | |
{ | |
NSString *overrideFontName = self.overrideFontName; | |
if (overrideFontName != nil) | |
{ | |
font = [UIFont fontWithName:overrideFontName size:font.pointSize]; | |
} | |
[super setFont:font]; | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment