Skip to content

Instantly share code, notes, and snippets.

@redent
Created December 6, 2013 18:56
Show Gist options
  • Star 10 You must be signed in to star a gist
  • Fork 3 You must be signed in to fork a gist
  • Save redent/7830234 to your computer and use it in GitHub Desktop.
Save redent/7830234 to your computer and use it in GitHub Desktop.
Categories for specifying custom fonts in Interface Builder and Storyboard. More info here: http://stackoverflow.com/a/15155081/469218
#import <UIKit/UIKit.h>
@interface UIButton (TCCustomFont)
@property (nonatomic, copy) NSString* fontName;
@end
@implementation UIButton (TCCustomFont)
- (NSString *)fontName {
return self.titleLabel.font.fontName;
}
- (void)setFontName:(NSString *)fontName {
self.titleLabel.font = [UIFont fontWithName:fontName size:self.titleLabel.font.pointSize];
}
@end
@interface UILabel (TCCustomFont)
@property (nonatomic, copy) NSString* fontName;
@end
@implementation UILabel (TCCustomFont)
- (NSString *)fontName {
return self.font.fontName;
}
- (void)setFontName:(NSString *)fontName {
self.font = [UIFont fontWithName:fontName size:self.font.pointSize];
}
@end
@interface UITextField (TCCustomFont)
@property (nonatomic, copy) NSString* fontName;
@end
@implementation UITextField (TCCustomFont)
- (NSString *)fontName {
return self.font.fontName;
}
- (void)setFontName:(NSString *)fontName {
self.font = [UIFont fontWithName:fontName size:self.font.pointSize];
}
@end
@shawon-farah
Copy link

Hey, it's great, saved lots of time for me to set fonts programmatically for each item.

I have added category for UITextView same way as UITextField over here, but its not working. Can you help please.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment