【发布时间】:2014-05-22 23:38:56
【问题描述】:
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,但我仍然没有在删除按钮上看到红色。
【问题讨论】:
-
您是否尝试过设置色调颜色而不是标题文本属性?
-
你试过
[self.deleteBarButtonItem setTintColor:[UIColor redColor]];而不是setTitleTextAttributes:吗? -
我刚试过。很不幸的是,不行。设置
self.deleteBarButtonItem.tintColor什么也没做。
标签: ios uitableview uinavigationcontroller uibarbuttonitem uinavigationitem