Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.