And*_*nez 44 objective-c uibarbuttonitem tintcolor ios ios7
我有一个使用Storyboard的项目,每当我用segue推动一个视图控制器时,动态创建的条形按钮项始终是蓝色的.

这让我疯了.因为这个对象是动态创建的,所以我无法在IB中设置它的颜色(就像我以前的bar按钮项一样).
我尝试过的解决方案包括:
viewDidLoad将它设置在接收器中 viewDidAppear
self.navigationItem.backBarButtonItem.tintColor = [UIColor whiteColor];
当我看到它不起作用时,我尝试设置leftBarButtonItem:
self.navigationItem.leftBarButtonItem.tintColor = [UIColor whiteColor];
我在我的应用程序的委托中尝试了以下代码(我从其他SO答案中获得),当调用新视图时,以及在推送新视图之前:
[[UIBarButtonItem appearance] setTintColor:[UIColor whiteColor]];
我发现所有谷歌的答案都建议使用上面的代码,但它对我来说根本不起作用.也许iOS 7的外观API有一些变化?无论我如何或在何处尝试将"Categorías"设置为白色,它始终是默认的蓝色.
hgw*_*tle 83
在iOS 7中,要设置应用程序中所有barButtonItem的颜色,请tintColor在AppDelegate中的应用程序窗口中设置该属性.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window.tintColor = [UIColor whiteColor];
return YES;
}
Run Code Online (Sandbox Code Playgroud)
Apple iOS 7 UI过渡指南中的更详细信息(特别是在"使用色调颜色"部分下).
***要么***
根据一些注释,您还可以使用UINavigationBar外观代理实现此目的.这将仅影响UIBarButtonItems的tintColor,而不是在窗口上设置tintColor并影响该窗口的所有子视图.
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
if([UINavigationBar conformsToProtocol:@protocol(UIAppearanceContainer)]) {
[UINavigationBar appearance].tintColor = [UIColor whiteColor];
}
return YES;
}
Run Code Online (Sandbox Code Playgroud)
小智 23
我认为您正在寻找UINavigationBar的属性.尝试设置self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
请参阅"导航栏的外观"部分:https://developer.apple.com/library/ios/documentation/userexperience/conceptual/UIKitUICatalog/UINavigationBar.html#//apple_ref/doc/uid/TP40012857-UINavigationBar-SW1
Ash*_*k R 10
在Swift 3.0中
let navigationBarAppearnce = UINavigationBar.appearance()
Run Code Online (Sandbox Code Playgroud)
导航栏的tintColor会影响后指示图像,按钮标题和按钮图像的颜色.
navigationBarAppearnce.barTintColor = UIColor(red: 0.180, green: 0.459, blue: 0.733, alpha: 1.00)
Run Code Online (Sandbox Code Playgroud)
barTintColor属性会影响条形本身的颜色
navigationBarAppearnce.tintColor = UIColor.white
Run Code Online (Sandbox Code Playgroud)
最终守则
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
let navigationBarAppearnce = UINavigationBar.appearance()
navigationBarAppearnce.barTintColor = UIColor(red: 0.180, green: 0.459, blue: 0.733, alpha: 1.00)
navigationBarAppearnce.tintColor = UIColor.white
navigationBarAppearnce.titleTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
//Change status bar color
UIApplication.shared.statusBarStyle = .lightContent
return true
}
Run Code Online (Sandbox Code Playgroud)
斯威夫特 5
barButtonItem.setTitleTextAttributes([NSAttributedString.Key.foregroundColor : UIColor.white], for: .normal)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
51586 次 |
| 最近记录: |