Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change default font to custom fonts in whole app

I want to keep custom fonts in iOS app. Currently, I'm using iOS default fonts. Is there any possible way for the same?

How do I include the custom font so that I can use it?

like image 945
user1066642 Avatar asked Jan 01 '15 12:01

user1066642


People also ask

How do I change my font default font?

Go to Format > Font > Font. + D to open the Font dialog box. Select the font and size you want to use. Select Default, and then select Yes.


1 Answers

Make a category:

#import "UILabel+Helper.h"

@implementation UILabel (Helper)
- (void)setSubstituteFontName:(NSString *)name UI_APPEARANCE_SELECTOR {
     self.font = [UIFont fontWithName:name size:self.font.pointSize]; } 
@end

Then in AppDelegate.m:

[[UILabel appearance] setSubstituteFontName:@"SourceSansPro-Regular"];

This will change font in whole app even on UIButton, UILabel, inside UITableViewCell, UICollectionViewCell, UIView, UIContainerView, or anywhere in application without changing the font point size.

This is memory efficient approach rather than enumerating all views in your UIViewController.

like image 192
Zeeshan Avatar answered Oct 22 '22 16:10

Zeeshan