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

北战南征 提交于 2019-12-22 02:51:51

问题


I am creating UILabel, for the label i can set the font name as HelveticaNeue Regular, Light, UltraLight etc, But i unable to set the font name as HelveticaNeue Thin, it is not working as expected. I did like,

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

Also i have searched on Google didnt got any solution. How to fix this issue? Thanks.


回答1:


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




回答2:


Updated answer to support swift

    let font = UIFont(name: "HelveticaNeue-Thin", size: 16.0)!



回答3:


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?




回答4:


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]];


来源:https://stackoverflow.com/questions/22091367/how-to-set-font-name-of-uilabel-as-helveticaneue-thin-in-ios

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!