titleTextAttributes iOS 7中的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
Edit 1
我实际上已经使用 [UINavigationBar外观]
问题是我将点大小设置为0才能拥有字体设置为默认的navbar / barButtonItem大小,如 NSString UIKit Additions Reference 但这显然不再适用于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
设置为
[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.
这篇关于titleTextAttributes iOS 7中的UIAppearance字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!