簡體   English   中英

如何更改導航欄的背景顏色和導航文本顏色

[英]how to change background color of the navigation bar and navigation text color

我希望導航欄的背景顏色為黑色,而導航欄上的文本為白色。

如下所示,在我的模擬器上一切正常:

在此處輸入圖片說明

但是,當我在帶有7.1的實際設備上對其進行測試時,即使導航欄的背景色為橙色,屏幕的標題也為黑色。

這是我在應用程序委托中所做的事情:

@window.rootViewController = UINavigationController.alloc.initWithRootViewController(main_controller)
@window.rootViewController.navigationBar.barTintColor = '#DF533B'.to_color
@window.rootViewController.navigationBar.translucent = true
@window.rootViewController.navigationBar.tintColor = UIColor.whiteColor
@window.rootViewController.navigationBar.setTitleTextAttributes({
    UITextAttributeTextColor => UIColor.whiteColor
})

我的deployment_target7.0app.sdk_version7.1

我是否應該將此代碼放入所有控制器的viewDidLoad中?

不熟悉RubyMotion,但是您應該使用UIAppearance代理:

[[UINavigationBar appearance] setBarTintColor:[self navBarColor]];

[[UINavigationBar appearance] setTintColor:[self navBarTitleColor]];

[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName : [self navBarTitleColor], NSFontAttributeName : [self titleFont]}];

在將主窗口加載到AppDelegate中之前,應執行此操作。

只是要添加到對我來說似乎正確的Moby答案中,請確保將其添加到應用程序委托的didFinishLaunchingWithOptions中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM