禁用 uibarbuttonitem 的文本颜色始终为正常状态的颜色 [英] text color of disabled uibarbuttonitem is always the color of the normal state

查看:38
本文介绍了禁用 uibarbuttonitem 的文本颜色始终为正常状态的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写在我的代码中

[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]  setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor lightGrayColor], NSFontAttributeName:[UIFont boldSystemFontOfSize:16.0f]} forState:UIControlStateDisabled];

[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]  setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor blueColor], NSFontAttributeName:[UIFont boldSystemFontOfSize:16.0f]} forState:UIControlStateNormal];

尽管禁用了baritem,但文本颜色始终为蓝色.

but the text color is always blue despite the baritem being disabled.

我正在使用 xcode 5 和 ios7 进行编程

I'm programming in xcode 5 and ios7

推荐答案

对我来说按照 code 工作.

for me following code works.

- (void)viewDidLoad {
    [super viewDidLoad];

    UIBarButtonItem * btnTemp = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(btnDone_Click:)];
    [btnTemp setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor lightGrayColor], NSFontAttributeName:[UIFont boldSystemFontOfSize:16.0f]} forState:UIControlStateNormal];

    [btnTemp setTitleTextAttributes:@{NSForegroundColorAttributeName : [UIColor blueColor], NSFontAttributeName:[UIFont systemFontOfSize:16.0f]} forState:UIControlStateDisabled];


    [self.navigationItem setRightBarButtonItem:btnTemp];

}

- (void)btnDone_Click : (id)sender {

    UIBarButtonItem * button = (UIBarButtonItem *)sender;
    [button setEnabled:FALSE];
    [self performSelector:@selector(enableButton:) withObject:sender afterDelay:2.0f];


}

- (void)enableButton : (id)sender {
    UIBarButtonItem * button = (UIBarButtonItem *)sender;
    [button setEnabled:TRUE];
}

这篇关于禁用 uibarbuttonitem 的文本颜色始终为正常状态的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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