外观代理无法按预期用于 UIButton 字体 [英] appearance proxy not working as intended for UIButton font

查看:17
本文介绍了外观代理无法按预期用于 UIButton 字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前通过外观代理为我的应用程序设计样式,但我遇到了这个问题:当我在 UIButton 外观上设置属性时,我的字体被忽略:

im currently styling my app via the appearance proxy and i ran into this problem: when i set properties on the UIButton appearance my font is ignored:

[buttonAppearance setTitleColor:darkColor forState:UIControlStateNormal];
[buttonAppearance.titleLabel setFont:[UIFont fontWithName:@"Helvetica Neue" size:10.0]];

第一行应用正确(darkColor 是一些 UIColor),但我的字体更改被完全忽略.当我将该行复制到我的 ViewController 并将其应用于具体按钮时,它工作正常.

the first line is applied properly (darkColor is some UIColor), but my font change is ignored completely. When i copy the line into my ViewController and apply it to a concrete button it works fine.

我错过了什么吗?

感谢任何帮助!ty

推荐答案

字体名称错误,应该是HelveticaNeue,中间没有空格.

The font name is wrong, it should be HelveticaNeue, without the space between.

以后如果您想查看其他 iOS 字体名称,您应该查看 本网站代码

In the future if you want to see other iOS font names you should check this website piece of code

编辑

仔细查看后,我意识到您正在尝试设置按钮标题的外观,它是 UILabel,遗憾的是 UILabel 没有字体属性UIAppearance 代理,这就是字体不起作用的原因.

After a closer look I realized that you are trying to set the appearance of the button's title which is a UILabel, sadly UILabel doesn't have the font property in the UIAppearance proxy and that's why the font doesn't work.

这篇关于外观代理无法按预期用于 UIButton 字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆