您如何setTitleTextAttributes:forState:在UIBarItemin中使用iOS?
setTitleTextAttributes:forState:
UIBarItem
iOS
您如何设置NSDictionary?无法使其正常运行,并且文档对此不太清楚。
NSDictionary
从文档中:
为给定的控件状态设置标题的文本属性:
- (void)setTitleTextAttributes:(NSDictionary *)attributes forState:(UIControlState)state
参数:
attribute:一个字典,其中包含文本属性的键值对。您可以使用NSString UIKit Additions Reference中列出的键来指定字体,文本颜色,文本阴影颜色和文本阴影偏移。
state:要为其设置标题文本属性的控件状态。
示例代码:
[[UIBarItem appearance] setTitleTextAttributes: [NSDictionary dictionaryWithObjectsAndKeys: [UIColor colorWithRed:220.0/255.0 green:104.0/255.0 blue:1.0/255.0 alpha:1.0], UITextAttributeTextColor, [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:1.0], UITextAttributeTextShadowColor, [NSValue valueWithUIOffset:UIOffsetMake(0, 1)], UITextAttributeTextShadowOffset, [UIFont fontWithName:@"AmericanTypewriter" size:0.0], UITextAttributeFont, nil] forState:UIControlStateNormal];