iOS 7 中的 titleTextAttributes UIAppearance 字体 [英] titleTextAttributes UIAppearance font in iOS 7
问题描述
我正在使用 UIAppearance 将字体应用于 UINavigationBar 和 UIBarButtonItem,但我遇到了问题.我运行了这段代码:
I am using UIAppearance to apply fonts to UINavigationBar and UIBarButtonItem and I am having problems. I ran this code:
[[UIBarButtonItem appearanceWhenContainedIn:[UIToolbar class], nil]
setTitleTextAttributes:
@{NSFontAttributeName : [UIFont fontWithName:@"My_Font" size:17.0]}
forState:UIControlStateNormal];
NSLog(@"%@", [[UIBarButtonItem appearanceWhenContainedIn:
[UIToolbar class], nil] titleTextAttributesForState:UIControlStateNormal]);
在 iOS 7 上登录的结果是:
and the result of that log on iOS 7 is:
(null)
iOS 6 中的结果在哪里:
Where the result in iOS 6 is:
{
NSFont = "<UICFFont: 0x1d897a80> font-family: "My_Font"; font-weight: normal; font-style: normal; font-size: 17px";
}
我在 iOS 7 文档中找不到任何表明这不可行的内容,有其他人遇到过这个问题吗?
I can't find anything in the iOS 7 docs that would indicate that this shouldn't work, has anyone else had this problem?
编辑 1
我实际上已经让它与 [UINavigationBar 外观]
一起使用,问题是我将点大小设置为 0,以便将字体设置为默认的导航栏/barButtonItem 大小作为NSString UIKit Additions 中描述参考,但这显然不再适用于 iOS 7.相反,将磅值设置为 0 将返回系统字体.
I actually have gotten this to work with [UINavigationBar appearance]
the problem was that I was setting the point size to 0 in order to have the font be set to the default navbar/barButtonItem size as described in the NSString UIKit Additions Reference but this apparently no longer works in iOS 7. Instead, setting the point size to 0 will return the system font.
我仍然无法将 titleTextAttributes
设置为
I am still unable to set titleTextAttributes
to
[UIBarButtonItem appearanceWhenContaintedIn:[UIToolbar class], nil]]
推荐答案
NSDictionary *attributes = [NSDictionary dictionaryWithObjectsAndKeys:[UIFont
fontWithName:@"YOURFONT" size:14], NSFontAttributeName,
[UIColor whiteColor], NSForegroundColorAttributeName, nil];
[[UINavigationBar appearance] setTitleTextAttributes:attributes];
关键是使用NSFontAttributeName等等.我假设他们正在转向使用 NS 品种以实现 64 位兼容性.以上代码适用于我的 iOS7 设备.
The key is to use NSFontAttributeName and so forth. I assume they are moving over to using the NS variety for 64-bit compatibility. The above code worked on my iOS7 device.
这篇关于iOS 7 中的 titleTextAttributes UIAppearance 字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!