MFMessageComposeViewController appearance iOS 7
Asked Answered
O

2

9

I have an appearance proxy that sets the barTintColor property to green on UINavigationBar

[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:54./255 green:165./255 blue:53./255 alpha:1]];

As needed I override this using appearanceWhenContainedIn:

[[UINavigationBar appearanceWhenContainedIn:[INFSearchViewController class], nil] setBarTintColor:[UIColor colorWithWhite:0.80 alpha:1]];

This works fine.

However when I present an MFMessageComposeViewController it adheres to the UINavigationBar proxy and looks like the following.

enter image description here

Which obviously looks terrible, I would prefer MFMessageComposeViewController to not adhere to the proxy but attempting to do

[[UINavigationBar appearanceWhenContainedIn:[MFMessageComposeViewController class], nil] setBarTintColor:[UIColor whiteColor]];

has no affect.

What course of action should I take here?

Outline answered 26/9, 2013 at 0:21 Comment(3)
I was a bit confused by your problem's description. The term "Which obviously looks terrible" threw me for a loop, because it is so vague. Everything on iOS 7 looks terrible to me-- the flat look, the ugly keyboard, etc. So, was the difficult-to-read green text the specific problem you are trying to avoid?Fjord
It's a matter of getting the UIAppearance proxy working on the navigation bar in the compose message view. I'm not looking for design input. It's not respecting the appearance I set as I would expect it to.Outline
Detailed answer with screenshots. https://mcmap.net/q/574578/-recipients-field-of-mfmessagecomposeviewcontroller-doesn-39-t-show-in-ios-7Wagtail
H
6

The hacky way: set the appearance back to the default white, present the modal, set the appearance to styled when the modal returns.

Or, reverse your thinking. Leave the global appearance as the default. Then you can selectively apply the styled nav bar where appropriate.

If "where appropriate" ends up being 90% of the app, just set up a thin subclass of UIViewController (or whatever view controller you use a lot) and that use that where you want the appearance.

[[UINavigationBar appearanceWhenContainedIn:[MyStyledViewController class], nil] 
  setBarTintColor:[UIColor colorWithRed:54./255 green:165./255 blue:53./255 alpha:1]];

And in each .h file, set your view controller superclass to MyStyledViewController rather than plain old UIViewController.

Hausner answered 26/9, 2013 at 19:0 Comment(3)
You can also create an UINavigationController subclass and make it your navigation controller. This way, you don't have to mess with all your VCs.Japheth
@MarceloFabri Greg's suggestion is actually working great except for my UINavigationBars within UINavigationController so I did what seemed logical. Created a subclass as you mention and set the appearance when contained within my sub-class... Yet the appearance still isn't applied. Thoughts?Outline
Ok, this answer cleared things up. https://mcmap.net/q/1315854/-uinavigationbar-appearance-works-but-not-uinavigationbar-appearancewhencontained-in I had to specify the appearances separately. I thought I could just provide a list and it would apply to all in the list, not the hierarchical order of the list.Outline
J
5

After digging around and trying a few different suggestions I arrived at a nice, non-hacky solution using a UINavigationController subclass.

This allows me to style all wanted nav bars once using the appearance proxy, with the exception of the MFMessageComposeViewController and MFMailComposeViewController which I'd prefer to look standard in order to communicate to the user that they are using core iOS functionality.

1 - Create a UINavigationController subclass.

2 - Style your nav bar using the appearance proxy as you were, but now using appearanceWhenContainedIn:

[[UINavigationBar appearanceWhenContainedIn:[KCStyledNavController class], nil] setBarTintColor:[UIColor redColor]];
[[UINavigationBar appearanceWhenContainedIn:[KCStyledNavController class], nil] setTintColor:[UIColor whiteColor]];

3 - Go into your storyboard, select all the the UINavigationControllers you want styled and change their custom class to your styled one.

Jackknife answered 2/9, 2014 at 6:32 Comment(1)
Yeah, this is the same approach I am taking. Maybe it wasn't clear enough in the answer/comments. It seems the cleanest way to go about it. What's interesting is that Apple says to not style their stuff, yet they adhere to your appearance proxies. You would think they'd block them.Outline

© 2022 - 2024 — McMap. All rights reserved.