iOS 7.0及更高版本。
在AppDelegate.m中,我设置了我的全局tintColor:self.window.tintColor = myGlobalTintColor;
。
在我的表视图控制器中,我想在编辑表格视图单元格时在导航栏中显示红色垃圾桶按钮,我有:
- (void)setEditing:(BOOL)editing animated:(BOOL)animate {
[super setEditing:editing animated:animate];
if (editing) { // Start editing
self.deleteBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemTrash target:self action:@selector(deleteButtonPressed)];
[self.deleteBarButtonItem setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor redColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItems = @[self.deleteBarButtonItem];
}
}
尽管有一行代码将NSForegroundColorAttributeName
设置为[UIColor redColor],
,但我从未看到过红色。当它设置为.enabled = YES
的按钮时,我只是看到它的全局色调颜色,就像所有其他按钮一样:
我已经梳理了我的代码,而且我确定没有其他地方可以设置myGlobalTintColor
。值得注意的是,这个UITableViewController
是从故事板中实例化的。在AppDelegate.m中注释掉该行只会将所有内容发送回默认的蓝色tintColor
,但我仍然没有在删除按钮上获得红色。
答案 0 :(得分:0)
事实证明问题是我使用的是第三方库SDCAlertView
,而我正在设置
[[SDCAlertView appearance] setTintColor:globalTintColor];
出于某种原因,这导致我的所有UINavigationBar
个对象都采用它的tintColor。
我通过简单地替换上面的代码来解决这个问题:
[[SDCAlertView appearance] setButtonTextColor:globalTintColor];