【问题标题】:UIBarButtomItem tintColor not working if i change the appearance of UITextField如果我更改 UITextField 的外观,UIBarButtomItem tintColor 不起作用
【发布时间】:2015-03-24 02:30:35
【问题描述】:

我有一个 UIBarButtonItem 实例。
我想将 UIBarButtonItem 的 tintColor 更改为 orangeColor。
并且我还在 Appdelegate 中将 UITextField 的外观更改为 orangeColor。

// some view controller
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Done" style:UIBarButtonItemStylePlain target:nil action:nil];

[barButtonItem setTintColor:[KLStyle colorTitleOrangle]];


// Appdelegate.h
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[UITextField appearance] setTintColor:[UIColor orangeColor]];
}

如果我不评论 [[UITextField appearance] setTintColor:[UIColor orangeColor]]; 会有问题,UIBarButtonItem 的 tintColor 会出错。它仍然是默认的 tintColor blue。

如果我评论它,UIBarButtonItem 的 tintColor 将是正确的。

有人知道为什么会发生这种情况吗?

感谢您的帮助!

【问题讨论】:

  • 奇怪的是,我也遇到了同样的问题。我认为这是一个错误,并将向 Apple 提交报告,我建议您也这样做。
  • 感谢您的报告!
  • 伙计...刚遇到这个问题。把我该死的头撞在墙上!直到我已经弄清楚了,我才看到这个答案...... :(
  • 我也有同样的问题
  • UIBarButtonItem的tintColor会出错以及设置UIImage的tintColor外观

标签: ios uitextfield uibarbuttonitem uiappearance


【解决方案1】:

解决方法:

[[UITextField appearanceWhenContainedIn:[UISearchBar class], nil] setTintColor: [UIColor lightGrayColor]];
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                                              [UIColor colorWithRed:24.0/255 green:75.0/255 blue:152.0/255 alpha:1],
                                                                                              NSForegroundColorAttributeName,
                                                                                              [UIColor grayColor],
                                                                                              NSForegroundColorAttributeName,
                                                                                              [NSValue valueWithUIOffset:UIOffsetMake(0, 1)],
                                                                                              NSForegroundColorAttributeName,
                                                                                              nil]
                                                                                              forState:UIControlStateNormal];
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
                                                                                              [UIColor grayColor],
                                                                                              NSForegroundColorAttributeName,
                                                                                              [UIColor grayColor],
                                                                                              NSForegroundColorAttributeName,
                                                                                              [NSValue valueWithUIOffset:UIOffsetMake(0, 1)],
                                                                                              NSForegroundColorAttributeName,
                                                                                              nil]
                                                                                       forState:UIControlStateDisabled];

【讨论】:

    猜你喜欢
    • 2019-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多