How to set font name of UILabel as HelveticaNeue Thin in iOS?

蓝咒 提交于 2019-12-04 22:51:34

This font is bundled with iOS 7, so if you're targeting iOS 7 and above your

label.font = [UIFont fontWithName:@"HelveticaNeue-Thin" size:16.0f];

will work.

However if you are targeting iOS 6.1 and below you'll need to embed the font

Updated answer to support swift

    let font = UIFont(name: "HelveticaNeue-Thin", size: 16.0)!
codercat
UIFontDescriptor *helveticaNeueFamily =
    [UIFontDescriptor fontDescriptorWithFontAttributes:
        @{ UIFontDescriptorFamilyAttribute: @"Helvetica Neue" }];
NSArray *matches =
    [helveticaNeueFamily matchingFontDescriptorsWithMandatoryKeys: nil];

The matchingFontDescriptorsWithMandatoryKeys: method as shown returns an array of font descriptors for all the Helvetica Neue fonts on the system, such as HelveticaNeue, HelveticaNeue-Medium, HelveticaNeue-Light, HelveticaNeue-Thin, and so on.

You can modify the fonts returned by preferredFontForTextStyle: by applying symbolic traits, such as bold, italic, expanded, and condensed. You can use font descriptors to modify particular traits, as shown in Listing 9-2.

referenced by apple

or

this font you can't apply directly.

so you can customize your font

How to use custom fonts in iPhone SDK?

This has worked for me. Write this code below your label declarations.

It sets all the UILabel under a function with same font.

[[UILabel appearance]setFont:[UIFont fontWithName:@"HelveticaNeue-Thin" size:32.0f]];

To set font to particular UILabel use this code :

[labelName setFont:[UIFont fontWithName:@"HelveticaNeue-Thin" size:15.0f]];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!