Skip to content

Instantly share code, notes, and snippets.

@softmaxsg
Created April 2, 2015 19:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save softmaxsg/8a3ce30331f9f07f023e to your computer and use it in GitHub Desktop.
Save softmaxsg/8a3ce30331f9f07f023e to your computer and use it in GitHub Desktop.
UILabel with automatic overriding font property with specific font face
#import <UIKit/UIKit.h>
@interface UILabelEx : UILabel
@property (nonatomic) NSString *overrideFontName;
@end
#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