Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UINavigationBar Appearance on Modal Not Setting

I am using the following code in my appDelegate to set the appearance of my UINavigationBar and status bar throughout my app:

[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

This code correctly sets the appearance of everything to white everywhere except when a third-party modal viewController is prevented, such as from the Dropbox API or the Mail/Message viewController from a UIActivityViewController. I've included some screenshots to show how these are looking.

UIActivityViewController Mail: UIActivityViewController Mail

UIActivityViewController Message: UIActivityViewController Message

Dropbox API: Dropbox API

I tried putting this in

[[UINavigationBar appearanceWhenContainedIn:[MFMailComposeViewController class], nil] setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor whiteColor]}];

as well as

[[UINavigationBar appearanceWhenContainedIn:[UIActivityViewController class], nil] setTintColor:[UIColor whiteColor]];

and neither one is working.

like image 647
Nick Avatar asked Jan 14 '14 01:01

Nick


People also ask

How do I change the navigation bar on my Iphone?

A user changes the navigation bar's style, or UIBarStyle , by tapping the “Style” button to the left of the main page. This button opens an action sheet where users can change the background's appearance to default, black-opaque, or black- translucent.

What is Scrolledgeappearance?

The appearance settings for the navigation bar when the edge of scrollable content aligns with the edge of the navigation bar.


1 Answers

Like you, I've been trying to alter the appearance of UIActivityViewController and it's "sub" controllers. It seems that in iOS7 the appearance API is somewhat buggy. UIActivityViewController is probably a different process and for sure a separate window, so I'm not really surprised that it's troublesome to style it.

Anyway I found an interesting way around this issue, but your designers might not like it. Create a subclass of UIWindow (ex: MyWindow), instantiate it as your main window and every time you use appearance API use it like this:

[UINavigationBar appearanceWhenContainedIn:[MyWindow class], nil].barTintColor = [UIColor redColor];

This way you'll only style views that actually belong to your application and the Apple-provided views will remain white/blue. I guess it's not the solution you were looking for, but on the other hand it gives users a good understanding what is your app and what is system-provided ;)

like image 119
Błażej Avatar answered Oct 01 '22 14:10

Błażej