[英]UIBarButtonItem Title Text is Always Global Tint Color
iOS 7.0 and up. iOS 7.0及更高版本。
In AppDelegate.m, I'm setting my global tintColor: self.window.tintColor = myGlobalTintColor;
在AppDelegate.m中,我设置了全局tintColor: self.window.tintColor = myGlobalTintColor;
. 。
In my table view controller where I want a red trash can button in the navigation bar while editing the table view cells, I have this: 在我的表格视图控制器中,在编辑表格视图单元格时,我想要导航栏中的红色垃圾桶按钮,它具有以下功能:
- (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];
}
}
Despite the line of code that is setting NSForegroundColorAttributeName
to [UIColor redColor],
I never see the red color. 尽管代码NSForegroundColorAttributeName
设置为[UIColor redColor],
我从未见过红色。 When the button it set to .enabled = YES
, I simply see it in my global tint color, like all the other buttons: 当按钮设置为.enabled = YES
,就像其他所有按钮一样,我只是以全局色查看它:
I've combed through my code and I'm sure there are no other locations where I'm setting anything else to myGlobalTintColor
. 我已经检查了我的代码,并且确定没有其他地方要对myGlobalTintColor
其他设置。 It's worth noting that this UITableViewController
is instantiated from a storyboard. 值得注意的是,此UITableViewController
是从情节UITableViewController
中实例化的。 Commenting out the line in AppDelegate.m just sends everything back to the default blue tintColor
, but I still don't get the red color on the delete button. 注释掉AppDelegate.m中的行只是将所有内容发送回默认的蓝色tintColor
,但是在删除按钮上我仍然看不到红色。
It turns out the problem was that I was using a third party library, SDCAlertView
, and I was setting 原来的问题是我正在使用第三方库SDCAlertView
,并且我正在设置
[[SDCAlertView appearance] setTintColor:globalTintColor];
For some reason, this caused all of my UINavigationBar
objects to take on it's tintColor. 由于某种原因,这导致我的所有UINavigationBar
对象都采用了tintColor。
I fixed this by simply replacing the above code: 我通过简单地替换上面的代码来解决此问题:
[[SDCAlertView appearance] setButtonTextColor:globalTintColor];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.