UIBarButtonItem 标题文本始终为全局色调 [英] UIBarButtonItem Title Text is Always Global Tint Color

查看:24
本文介绍了UIBarButtonItem 标题文本始终为全局色调的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

iOS 7.0 及更高版本.

iOS 7.0 and up.

在 AppDelegate.m 中,我正在设置我的全局 tintColor:self.window.tintColor = myGlobalTintColor;.

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];
    }
}

尽管代码行将 NSForegroundColorAttributeName 设置为 [UIColor redColor], 我从未看到红色.当按钮设置为 .enabled = YES 时,我只是在我的全局色调中看到它,就像所有其他按钮一样:

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:

我已经梳理了我的代码,我确定没有其他位置可以为 myGlobalTintColor 设置任何其他内容.值得注意的是,这个 UITableViewController 是从故事板实例化的.注释掉 AppDelegate.m 中的行只是将所有内容发送回默认的蓝色 tintColor,但我仍然没有在删除按钮上看到红色.

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.

推荐答案

原来问题是我用的是第三方库,SDCAlertView,我在设置

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

[[SDCAlertView appearance] setTintColor:globalTintColor];

出于某种原因,这导致我所有的 UINavigationBar 对象都采用了 tintColor.

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];

这篇关于UIBarButtonItem 标题文本始终为全局色调的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆