如何在UIBarItem中使用setTitleTextAttributes:forState? [英] How do you use setTitleTextAttributes:forState in UIBarItem?

查看:161
本文介绍了如何在UIBarItem中使用setTitleTextAttributes:forState?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在iOSUIBarItem中使用setTitleTextAttributes:forState:?

如何设置NSDictionary?无法使其正常运行,并且文档对此不太清楚.

How do you set the NSDictionary? Can't make it work and documentation isn't very clear about that.

来自文档:

setTitleTextAttributes:forState:

设置给定控件状态的标题文本属性:

- (void)setTitleTextAttributes:(NSDictionary *)attributes 
                      forState:(UIControlState)state

参数:

属性:一个字典,其中包含文本属性的键值对.您可以使用NSString UIKit Additions Reference中列出的键来指定字体,文本颜色,文本阴影颜色和文本阴影偏移.

attributes: A dictionary containing key-value pairs for text attributes. You can specify the font, text color, text shadow color, and text shadow offset using the keys listed in NSString UIKit Additions Reference.

state:要为其设置标题文本属性的控件状态.

state: The control state for which you want to set the text attributes for the title.

推荐答案

示例代码:

    [[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];

这篇关于如何在UIBarItem中使用setTitleTextAttributes:forState?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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