UINavigationBar appearance setTintColour not working on ActivityItems - ios

I'm trying to set the colour of the cancel buttonBarItem to white on the Message / Mail activityItems presented with the UIActivityViewController but whatever I do it doesn't change them.
The cancel remains the standard default blue used in iOS7 as do other items in these views that ideally I would like to change. I've tried using the code below in the AppDelegate which sets the colour correctly throughout the rest of the app but it doesn't work when these views are presented.
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
These settings do retain their values when added to AppDelegate and these views are presented as can be seen below.
[[UINavigationBar appearance] setBarTintColor:SOLIDTEALCOLOR];
[[UINavigationBar appearance] setTitleTextAttributes:#{ NSForegroundColorAttributeName: [UIColor whiteColor]}];
Do I need to roll my own ActivityViewController using bespoke SLComposeViewControllers for each activityItem to have this degree of control this colour? It seem like an unnecessary large amount of work for something that really shouldn't be an issue.

Related

In Objective C, while presenting a ViewController how to change the color of NavigationBar?

I am able to change tho color of NavigationBar by giving BackgroundColor but than I am not able change the color of StatusBar. Please provide a solution.
You should change the barTintColor instead of the background color.
[self.navigationController setBarTintColor:[UIColor redNavigationBarColor]];
Chances are that you will probably need to change also the barButton color and/or the the title color and all that should probably apply to more than one screen. So, to save you some time, if you want to globally change all these, put the code below in your app delegate
[[UINavigationBar appearance] setBarTintColor:[UIColor redColor]];
[[UINavigationBar appearance] setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor whiteColor]}];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
The code above will give you a red navigation bar with white title & buttons

UINavigationBar not updating Color immediately

I am trying to change the color of the UINavigationBar as the User navigates to a different page. However my App does not change the color of the UINavigationBar until the user backs out of the page and goes back into the page once again. I tried putting the initialization code for changing the color in -(void)viewDidLoad and also -(void)viewWillAppear:(BOOL)animated. Here is how I am currently attempting to change the color:
-(void)viewWillAppear:(BOOL)animated{
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0.32f green:0.14f blue:0.32f alpha:1.00f]];
}
You should use something like that:
-(void)viewWillAppear:(BOOL)animated{
[self.navigationController.navigationBar setBarTintColor:[UIColor colorWithRed:0.32f green:0.14f blue:0.32f alpha:1.00f]];
}
That code you have changes title bar color for ALL UINavigationBar instances. It's application wide proxy. You don't want to use it if you need to change it in just one place.

iOS 7.1 UINavigationbar and UIToolbar

After upgrading Xcode in iOS7.1 my navigation bar and UIToolbar buttons are not shown with correct colour.
When a view first appears the UIToolbar buttons all have the correct default blue colour and when I go to next page/view and come back to the previous view the toolbar buttons are shown in a grey colour.
I have tried to add the blue colour in viewDidLoad and viewWillAppear but no luck. Can someone please help me?
Thanks.
You can set up a theme for certain components all at once and they will be used throughout your application. In my app delegate I created a function when the application is initializing called setupTheme, and it does just that - sets up the "theme" of the application by saying things like [[UINavigationBar appearance] setBarTintColor:], which in effect sets the color of the navigation bar for ANY navigation controller throughout the app. Here's an example from an app that sets up some basic components that are reused so that any time you use them they will already have the correct theme applied.
- (void)setupTheme {
// get our theme colors
UIColor *primaryThemeColor = [UIColor blueColor];
UIColor *secondaryThemeColor = [UIColor whiteColor];
// nav bar
[[UINavigationBar appearance] setBarTintColor:primaryThemeColor];
[[UINavigationBar appearance] setTintColor:secondaryThemeColor];
[[UINavigationBar appearance] setTitleTextAttributes:#{NSForegroundColorAttributeName:secondaryThemeColor}];
// tab bar
[[UITabBar appearance] setTintColor:primaryThemeColor];
// switches
[[UISwitch appearance] setOnTintColor:primaryThemeColor];
// search bar
[[UIBarButtonItem appearanceWhenContainedIn:[UISearchBar class], nil] setTitleTextAttributes:#{NSForegroundColorAttributeName: [UIColor blackColor]} forState:UIControlStateNormal];
}
Check out the iOS 7 transition guide for more details on specifics https://developer.apple.com/library/iOs/documentation/UserExperience/Conceptual/TransitionGuide/Bars.html#//apple_ref/doc/uid/TP40013174-CH8-SW1

MFMessageComposeViewController appearance iOS 7

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.
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?
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.
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.

Changing text color UINavigationBar

Hi i'm working on an iOS project that uses the MFMailComposeViewController to send out an email.
I changed the title bar to use an image
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"project_headerbg"] forBarMetrics:UIBarMetricsDefault];
but now when I click on the '+' button next to CC I can't read the text "Choose a contact to mail" in the header very well and was wondering if there was a way to change the color of that text?
Thanks
This question has nothing to do with using the MFMailComposeViewController. If you wish to customize the appearance of a UINavigationBar, then you may need to set more properties than just the background image. You should also setup the titleTextAttributes.
// Use whatever color is appropriate
NSDictionary *attributes = #{ UITextAttributeTextColor: [UIColor blueColor] };
[[UINavigationBar appearance] setTitleTextAttributes:attributes];
There are other attributes such as the font and shadow colors. Feel free to set the ones you need.

Resources