gpt4 book ai didi

ios - 更改 UIBarButtonItem 的 Tint 颜色

转载 作者:IT老高 更新时间:2023-10-28 11:39:53 32 4
gpt4 key购买 nike

我有一个使用 Storyboards 的项目,每当我使用 segue 推送 View Controller 时,动态创建的条形按钮项始终是蓝色的。

enter image description here

这让我发疯了。因为这个对象是动态创建的,所以我不能在 IB 中设置它的颜色(就像我对之前的条形按钮项目所做的那样)。

我尝试过的解决方案有:

  1. 在接收者的viewDidLoad
  2. 中设置
  3. 在接收者的viewDidAppear

    中设置

    self.navigationItem.backBarButtonItem.tintColor = [UIColor whiteColor];

  4. 当我发现这不太行时,我尝试设置 leftBarButtonItem:

self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];

  1. 在调用新 View 时以及在推送新 View 之前,我在应用程序的委托(delegate)中尝试了以下代码(我从其他 SO 答案中获得):

    [[UIBarButtonItem 外观] setTintColor:[UIColor whiteColor]];

我找到的所有谷歌答案都建议使用上面的代码,但它对我来说根本不起作用。或许 iOS 7 的外观 API 有一些变化?无论我如何或在何处尝试将“Categorías”设置为白色,它始终是默认的蓝色。

最佳答案

在 iOS 7 中,要设置应用程序中所有 barButtonItems 的颜色,请在 AppDelegate 中设置应用程序窗口的 tintColor 属性。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window.tintColor = [UIColor whiteColor];
return YES;
}

更多详细信息见 Apple's iOS 7 UI Transition Guide (特别是在“使用色调颜色”部分)。

***或***

根据一些评论,您也可以使用 UINavigationBar 外观代理来实现这一点。这将只影响 UIBarButtonItems 的 tintColor,而不是在窗口上设置 tintColor 并影响该窗口的所有 subview 。

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if([UINavigationBar conformsToProtocol:@protocol(UIAppearanceContainer)]) {
[UINavigationBar appearance].tintColor = [UIColor whiteColor];
}

return YES;
}

关于ios - 更改 UIBarButtonItem 的 Tint 颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19504291/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com