문제

I want the background color of the navigation bar to be black and the text on the navigation bar to be white.

Everything looks fine on my simulator as shown below:

enter image description here

However, when I test it on the actual device w/ 7.1, even though the background color of navigation bar is orange, the title of the screen is black.

This is what I'm doing in my application delegate:

@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
})

my deployment_target is 7.0 and app.sdk_version is 7.1

Should I be putting this code in viewDidLoad of all my controllers?

도움이 되었습니까?

해결책

Not familiar with RubyMotion, but you should use the UIAppearance proxy:

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

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

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

You should do this before you load your main window in your AppDelegate.

다른 팁

Just to add to Moby's answer which appears correct to me, Make sure you add it to the didFinishLaunchingWithOptions for your app delegate.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top