简体   繁体   English

无法在UILabel(iPad应用程序)中设置自定义字体

[英]Can't set custom Font in UILabel (iPad app)

I load view from bundle and try to set custom font for label in it, but nothing changes. 我从bundle加载视图并尝试在其中设置标签的自定义字体,但没有任何变化。 Outlets for this view and labels are in file's owner. 此视图和标签的出口位于文件所有者中。 Here's my code: 这是我的代码:

    self.rikView = (RIKMainToolbar*)[[[NSBundle mainBundle] loadNibNamed:@"RIKMainToolbarPort" owner:self options:nil] objectAtIndex:0];
    label.font = [UIFont fontWithName:@"PFDinTextCondPro-Medium.ttf" size:46];

What am I doing wrong? 我究竟做错了什么?

UPD: I use this font in iPhone app, but there it's using for label in ViewController and sets in viewDidLoad function. UPD:我在iPhone应用程序中使用此字体,但它在ViewController中用于标签并在viewDidLoad函数中设置。 And it works. 它有效。 So, I consider that problem is in loadWithNibName or in iPad. 所以,我认为问题出在loadWithNibName或iPad中。

Solved, thanks to @voromax. 解决了,感谢@voromax。 The problem was that labels' outlets belonged to file's owner. 问题是标签的出口属于文件所有者。 I've replace it with class and everything works) 我用类替换它,一切正常)

我不知道我按照你的代码完全,但假设你正在做在initWithFrame的label.font分配RIKMainToolbarPort ,尝试移动到awakeFromNib方法。

Open the FontBook application, and select "view font info". 打开FontBook应用程序,然后选择“查看字体信息”。 Copy the post-script-name of your desired font, and use that in your Obj-C code 复制所需字体的post-script-name,并在Obj-C代码中使用它

You are not using the correct font name. 您没有使用正确的字体名称。 You seem to be using the font file's name, NOT the font name. 您似乎使用的是字体文件的名称,而不是字体名称。 For example, in my current app I have the file Opal_1.ttf. 例如,在我当前的应用程序中,我有文件Opal_1.ttf。 However, I use "Opal" as the font name. 但是,我使用“Opal”作为字体名称。

[edit]Meh, check the example here: https://stackoverflow.com/a/1384206/855738 Again, I repeat, your font name is wrong . [编辑]嗯,请查看以下示例: https//stackoverflow.com/a/1384206/855738我再说一遍,你的字体名称是错误的 That's your problem... Why the down vote? 这是你的问题......为什么投票失败? :/ :/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM