xcode 如何以编程方式将字体设置为标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6568101/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:24:11  来源:igfitidea点击:

How to programmatically set font to labels

iphonexcode

提问by Ishu

How to set fonts to labels in Xcode 4?

如何在 Xcode 4 中为标签设置字体?

I tried this

我试过这个

mylabel.setfont = @"DBLCDTempBlack";

采纳答案by Rishabh

Try This

尝试这个

[mylabel setFont:[UIFont fontWithName:@"fontname" size:128.0]];

回答by Ishu

use one of following

使用以下之一

[mylabel setFont:[UIFont systemFontOfSize:13]];
[mylabel setFont:[UIFont boldSystemFontOfSize:13]];//or use this
myLabel.font=[UIFont systemFontOfSize:13]];//or
 mylabel.font=[UIFont boldSystemFontOfSize:13]//or

[mylabel setFont:[UIFont fontWithName:@"DBLCDTempBlack" size:128.0]];

also some other ways see developer documentation for creating UIFont

还有其他一些方法请参阅用于创建 UIFont 的开发人员文档

回答by Matteo Alessani

you need to use this syntax:

你需要使用这个语法:

[mylabel setFont:[UIFont fontWithName:@"DBLCDTempBlack" size:12.0f]];

you should pass a UIFont object to the function setFont. You can use some of this from http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIFont_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UIFont

您应该将 UIFont 对象传递给函数 setFont。您可以使用http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIFont_Class/Reference/Reference.html#//apple_ref/doc/c_ref/UIFont

fontWithName:size:
systemFontOfSize:
boldSystemFontOfSize:
italicSystemFontOfSize: