如何在 iOS 中将 UILabel 的字体名称设置为 HelveticaNeue Thin?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22091367/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set font name of UILabel as HelveticaNeue Thin in iOS?
提问by Surfer
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,
我正在创建 UILabel,对于标签,我可以将字体名称设置为 HelveticaNeue Regular、Light、UltraLight 等,但是我无法将字体名称设置为 HelveticaNeue Thin,它无法按预期工作。我喜欢,
label.font = [UIFont fontWithName:@"HelveticaNeue-Thin" size:16];
Also i have searched on Google didnt got any solution. How to fix this issue? Thanks.
我也在谷歌上搜索过没有任何解决方案。如何解决这个问题?谢谢。
回答by ncremins
This font is bundled with iOS 7, so if you're targeting iOS 7 and above your
此字体与 iOS 7 捆绑在一起,因此如果您的目标是 iOS 7 及更高版本
label.font = [UIFont fontWithName:@"HelveticaNeue-Thin" size:16.0f];
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
但是,如果您的目标是 iOS 6.1 及以下,则需要嵌入字体
回答by RiceAndBytes
Updated answer to support swift
更新答案以支持 swift
let font = UIFont(name: "HelveticaNeue-Thin", size: 16.0)!
回答by 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.
所示的 matchingFontDescriptorsWithMandatoryKeys: 方法返回系统上所有 Helvetica Neue 字体的字体描述符数组,例如 HelveticaNeue、HelveticaNeue-Medium、HelveticaNeue-Light、HelveticaNeue-Thin等。
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.
您可以修改 preferredFontForTextStyle 返回的字体:通过应用符号特征,例如粗体、斜体、扩展和压缩。您可以使用字体描述符来修改特定的特征,如清单 9-2 所示。
referenced by apple
被苹果引用
or
或者
this font you can't apply directly.
这种字体你不能直接应用。
so you can customize your font
所以你可以自定义你的字体
回答by aashish tamsya
This has worked for me. Write this code below your label declarations.
这对我有用。将此代码写在标签声明下方。
It sets all the UILabelunder a function with same font.
它将所有 UILabel 设置在具有相同字体的函数下。
[[UILabel appearance]setFont:[UIFont fontWithName:@"HelveticaNeue-Thin" size:32.0f]];
To set font to particular UILabeluse this code :
要将字体设置为特定 UILabel使用以下代码:
[labelName setFont:[UIFont fontWithName:@"HelveticaNeue-Thin" size:15.0f]];