Helvetica Neue Light,iOS
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18383070/
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
Helvetica Neue Light,iOS
提问by MattLoszak
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.
我正在尝试在我的 iPhone 应用程序中以编程方式使用 Helvetica Neue Light。似乎系统没有内置这个,这看起来很奇怪。
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];
回答by rckoenes
The font name you used is incorrect, try:
您使用的字体名称不正确,请尝试:
Objective-C
目标-C
myLabel.font = [UIFont fontWithName:@"HelveticaNeue-Light" size:32.0f];
Swift
迅速
myLabel.font = UIFont(name: "HelveticaNeue-Light", size: 32.0)
On iOS Fontsyou will find the full list of fonts and their names.
在iOS 字体上,您将找到字体及其名称的完整列表。
回答by Ahmed Z.
回答by aashish tamsya
UPDATE FOR SWIFT 3
更新 Swift 3
For the past few month, swift approach towards init
has changed, I would recommend not to use init
in Swift 3
在过去的几个月里,快速的方法init
已经改变,我建议不要init
在 Swift 3 中使用
label.font = UIFont(name: "HelveticaNeue-Light", size: 17.0)
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)
目标-C:
[label setFont:[UIFont fontWithName:@"HelveticaNeue-Light" size:17.0f]];
斯威夫特 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 UILabelunder a function with same font.
它将所有UILabel 设置在具有相同字体的函数下。
Objective-C :
目标-C:
[[UILabel appearance]setFont:[UIFont fontWithName:@"HelveticaNeue-Thin" size:32.0f]];
Swift 2.2 :
斯威夫特 2.2:
UILabel.appearance().font = UIFont.init(name: "HelveticaNeue-Thin", size: 32.0)
To set font to particular UILabeluse this code :
要将字体设置为特定UILabel使用以下代码:
Objective-C :
目标-C:
[labelName setFont:[UIFont fontWithName:@"HelveticaNeue-Thin" size:15.0f]];
Swift 2.2 :
斯威夫特 2.2:
label.font = UIFont.init(name: "HelveticaNeue-Light", size: 17.0)
回答by aftab muhammed khan
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.
我有一个建议,如果您喜欢使用 UIFont,请打印所有字体名称。所以将来你总是会得到正确的字体名称。
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);
}];
}];
}