【iOS开发-103】解决方案:iOS8.1中UIBarButtonItem的setTitleTextAttributes对Disabled颜色设置无效
2015-01-14 14:33
411 查看
(1)情景:在iOS8.1中,我们通常会利用如下语句,设置全局的导航条按钮item的主题
UIBarButtonItem *item=[UIBarButtonItem appearance];
NSMutableDictionary *textAttrs=[NSMutableDictionary dictionary];
textAttrs[NSForegroundColorAttributeName]=[UIColor orangeColor];
[item setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
[item setTitleTextAttributes:textAttrs forState:UIControlStateHighlighted];
NSMutableDictionary *dTextAttrs=[NSMutableDictionary dictionaryWithDictionary:textAttrs];
dTextAttrs[NSForegroundColorAttributeName]=[UIColor grayColor];
[item setTitleTextAttributes:dTextAttrs forState:UIControlStateDisabled];
(2)问题是,我们在上面明明设置了item各种状态下的属性(normal,highlighted和disabled),但是当我们在某一个控制器中添加了一个item时,并且设置为disabled状态时,却发现不起作用。
-(void)setupNavBar{
self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"发送" style:UIBarButtonItemStyleDone target:self action:@selector(send)];
self.navigationItem.rightBarButtonItem.enabled=NO;
}
(3)解决方案
将上面的设置为disabled的语句放置在viewWillAppear中。
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
//如果把下面这一句写在ViewDidLoad中,disabled的item颜色没有效果
self.navigationItem.rightBarButtonItem.enabled=NO;
}
(4)至于为什么会是这样?说实话,我也不是很清楚,之前以为调用顺序的原因(测试顺序正常),后来觉得是viewDidLoad中enabled未赋值(但测试是0,有赋值)。有明白的还请指教。暂且认为是iOS8.1的一个bug吧。在iOS7.1中测试是正常的。
UIBarButtonItem *item=[UIBarButtonItem appearance];
NSMutableDictionary *textAttrs=[NSMutableDictionary dictionary];
textAttrs[NSForegroundColorAttributeName]=[UIColor orangeColor];
[item setTitleTextAttributes:textAttrs forState:UIControlStateNormal];
[item setTitleTextAttributes:textAttrs forState:UIControlStateHighlighted];
NSMutableDictionary *dTextAttrs=[NSMutableDictionary dictionaryWithDictionary:textAttrs];
dTextAttrs[NSForegroundColorAttributeName]=[UIColor grayColor];
[item setTitleTextAttributes:dTextAttrs forState:UIControlStateDisabled];
(2)问题是,我们在上面明明设置了item各种状态下的属性(normal,highlighted和disabled),但是当我们在某一个控制器中添加了一个item时,并且设置为disabled状态时,却发现不起作用。
-(void)setupNavBar{
self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc]initWithTitle:@"发送" style:UIBarButtonItemStyleDone target:self action:@selector(send)];
self.navigationItem.rightBarButtonItem.enabled=NO;
}
(3)解决方案
将上面的设置为disabled的语句放置在viewWillAppear中。
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
//如果把下面这一句写在ViewDidLoad中,disabled的item颜色没有效果
self.navigationItem.rightBarButtonItem.enabled=NO;
}
(4)至于为什么会是这样?说实话,我也不是很清楚,之前以为调用顺序的原因(测试顺序正常),后来觉得是viewDidLoad中enabled未赋值(但测试是0,有赋值)。有明白的还请指教。暂且认为是iOS8.1的一个bug吧。在iOS7.1中测试是正常的。
相关文章推荐
- 【iOS开发-103】解决方案:iOS8.1中UIBarButtonItem的setTitleTextAttributes对Disabled颜色设置无效
- iOS开发解决:iOS8.1中UIBarButtonItem的setTitleTextAttributes对Disabled颜色设置无效问题
- iOS8中UIBarButtonItem的setTitleTextAttributes对Disabled颜色设置无效
- iOS 系统导航栏 UINavigationController 标题设置setTitleTextAttributes
- UITabBar 设置字体的颜色(选中状态/正常状态)setTitleTextAttributes
- IOS开发怎么UINavigationController设置title标题的颜色?
- iOS开发-设置导航栏title字体颜色
- iOS button.titleLabel和直接设置button setText
- Xamarin.Android 开发SetTextColor颜色设置
- android开发之形似“TextView.setTextColor(int)”括号里那个设置颜色的颜色int值的理解
- 安卓开发 给textview添加点击事件并设置点击颜色
- 利用SetConsoleTextAttribute函数设置控制台颜色
- iOS开发UITableViewCell的选中时的颜色设置
- Flex中如何设置TextArea控件中的无效(disabled)文本颜色的例子
- 利用SetConsoleTextAttribute函数设置控制台颜色
- iOS开发之navigation bar修改title颜色、字体等
- ios oc ui 路径和颜色设置--崩溃解决方案
- [iOS开发]Xcode5如何设置ARC有效/无效
- SetConsoleTextAttribute设置颜色后的恢复
- IOS开发 设置UIButton的title