Iphone 无法更改处于禁用状态的UIBarButtonim颜色属性
我创建了一个UIToolBar,其中包含三个工具栏按钮项。使用默认字体和字体大小时,所有这些都可以正常工作。但是,字体有点太大,我想调整它的大小。我使用以下代码成功地自定义了正常状态下的字体大小和颜色,但是当按钮1被禁用时,文本颜色在启用和禁用状态下都保持黑色,即不会将颜色更改为灰色Iphone 无法更改处于禁用状态的UIBarButtonim颜色属性,iphone,ios8,Iphone,Ios8,我创建了一个UIToolBar,其中包含三个工具栏按钮项。使用默认字体和字体大小时,所有这些都可以正常工作。但是,字体有点太大,我想调整它的大小。我使用以下代码成功地自定义了正常状态下的字体大小和颜色,但是当按钮1被禁用时,文本颜色在启用和禁用状态下都保持黑色,即不会将颜色更改为灰色 NSDictionary *ena = @{NSFontAttributeName:[UIFont fontWithName:@"Helvetica" size:12.0], NSForegroundColorAt
NSDictionary *ena = @{NSFontAttributeName:[UIFont fontWithName:@"Helvetica" size:12.0], NSForegroundColorAttributeName:
[UIColor blackColor]};
NSDictionary *dis = @{NSFontAttributeName:[UIFont fontWithName:@"Helvetica" size:12.0], NSForegroundColorAttributeName:
[UIColor grayColor]};
[[UIBarButtonItem appearance] setTitleTextAttributes:ena forState:UIControlStateNormal];
[[UIBarButtonItem appearance] setTitleTextAttributes:dis forState:UIControlStateDisabled];
如果您能给我一些反馈,告诉我上述代码哪里出了问题,我将不胜感激;假设是我的巴布顿。最初从情节提要中将其禁用。然后在ViewDidLoad中调用它
if (myBarButton.enabled == 'NO') {
NSDictionary *dis = @{NSFontAttributeName:[UIFont fontWithName:@"Helvetica" size:12.0], NSForegroundColorAttributeName:
[UIColor grayColor]};
[[UIBarButtonItem appearance] setTitleTextAttributes:ena forState:UIControlStateNormal];
}
然后在完成一些必要的工作后启用myBarButton,然后运行下面的代码
NSDictionary *dis = @{NSFontAttributeName:[UIFont fontWithName:@"Helvetica" size:12.0], NSForegroundColorAttributeName:
[UIColor blackColor]};
[[UIBarButtonItem appearance] setTitleTextAttributes:ena forState:UIControlStateNormal];
实际上,UIControlStateDisabled并不像我观察到的那样工作