![](/img/trans.png)
[英]How to change the font color / Text Color of the UIBarButtonItem on navigation bar
[英]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_target
是7.0
而app.sdk_version
是7.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.