UIBarButtonItem Title Text is Always Global Tint C

2019-07-15 08:38发布

iOS 7.0 and up.

In AppDelegate.m, I'm setting my global 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. When the button it set to .enabled = YES, I simply see it in my global tint color, like all the other buttons: UINavigationBar with always tinted UIBarButtonItem

I've combed through my code and I'm sure there are no other locations where I'm setting anything else to myGlobalTintColor. It's worth noting that this UITableViewController is instantiated from a storyboard. 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.

1条回答
再贱就再见
2楼-- · 2019-07-15 08:47

It turns out the problem was that I was using a third party library, SDCAlertView, and I was setting

[[SDCAlertView appearance] setTintColor:globalTintColor];

For some reason, this caused all of my UINavigationBar objects to take on it's tintColor.

I fixed this by simply replacing the above code:

[[SDCAlertView appearance] setButtonTextColor:globalTintColor];
查看更多
登录 后发表回答