Reputation: 585
Surprisingly I can't seem to find another question on this... sorry if I'm missing something obvious.
I'm trying to use Helvetica Neue Light programatically in my iPhone app. It seems that the system doesn't have this built in, which seems strange.
Is this the case? Does this particular font need to be added manually?
Ideally I'd like to edit this line of code to accomplish this:
myLabel.font = [UIFont fontWithName:@"HelveticaNeue" size: 32];
Upvotes: 30
Views: 37891
Reputation: 4959
UPDATE FOR SWIFT 3
For the past few month, swift approach towards init
has changed, I would recommend not to use init
in Swift 3
label.font = UIFont(name: "HelveticaNeue-Light", size: 17.0)
Objective- C :
[label setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:17.0f]];
Swift 2.2 :
label.font = UIFont.init(name: "HelveticaNeue-Light", size: 17.0)
UPDATE :
This has worked for me. Write this code below your label declarations.
It sets all the UILabel under a function with same font.
Objective-C :
[[UILabel appearance]setFont:[UIFont fontWithName:@"HelveticaNeue-Thin" size:32.0f]];
Swift 2.2 :
UILabel.appearance().font = UIFont.init(name: "HelveticaNeue-Thin", size: 32.0)
To set font to particular UILabel use this code :
Objective-C :
[labelName setFont:[UIFont fontWithName:@"HelveticaNeue-Thin" size:15.0f]];
Swift 2.2 :
label.font = UIFont.init(name: "HelveticaNeue-Light", size: 17.0)
Upvotes: 7
Reputation: 2186
I have one suggestion if you like to use UIFont please print all the font names. so in future you will always get correct font name.
You just need to paste method somewhere in you class and you will get the list of all system fonts
-(void)fontNames{
NSArray *familyNames = [UIFont familyNames];
[familyNames enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop){
NSLog(@"* %@",obj);
NSArray *fontNames = [UIFont fontNamesForFamilyName:obj];
[fontNames enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop){
NSLog(@"--- %@",obj);
}];
}];
}
Upvotes: 0