[[UINavigationBar appearance] setBackgroundImage:gradientImage44
forBarMetrics:UIBarMetricsDefault];
Would customize UINavigationBar
Say I have a class
BGImageBookController
I want UINavigationBar on top of BGImageBookController to have a different background. How would I do so?
I did this in viewDidload
- (void)viewDidLoad
{
[super viewDidLoad];
[[UINavigationBar appearanceWhenContainedIn:[BGImageBookController class], nil] setBackgroundImage:[UIImage imageNamed:#"sushi_eating_cat"] forBarMetrics:UIBarMetricsDefault];
}
no effect
This is your code:
[[UINavigationBar appearanceWhenContainedIn:[BGImageBookController class], nil] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
You just call setBackgroundImage:forBarMetrics: in the viewDidLoad method of the BGImageBookController.
Related
I am having issues modifying color on a UINavigation bar. I feel like I have tried everything, but my current code is below (MasterViewController.m, my main view):
-(void)awakeFromNib{
[super awakeFromNib];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0.9333 green:0.3647 blue:0.3843 alpha:1.0]];
[[UINavigationBar appearance] setBackgroundColor:[UIColor colorWithRed:0.9333 green:0.3647 blue:0.3843 alpha:1.0]];
[[UINavigationBar appearance] setTranslucent:NO];
}
Here is my setup in my storyboard:
Any apparent reason why this isn't working?
In my iOS application, I am using the DocumentInteractionController to preview the .csv document.
self.documentController = [UIDocumentInteractionController interactionControllerWithURL:fileLocation];
[self.documentController setDelegate:self];
[self.documentController presentPreviewAnimated:YES];
However, I am finding that the navigation bar is completely transparent. The back button is white, so it is not visible due to the white background.
Note that I have styled the navigation bar in the AppDelegate:
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:0/255.0f green:138/255.0f blue:188/255.0f alpha:1.0f]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTitleTextAttributes:#{NSFontAttributeName:[UIFont fontWithName:#"DINPro-Bold" size:17]}];
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setShadowImage:[UIImage imageNamed:#"shadow"]];
[[UITabBar appearance] setSelectedImageTintColor:[UIColor whiteColor]];
[[UITabBar appearance] setTintColor:[UIColor whiteColor]];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];
Essentially, my question is how can I make the appearance of the navigation bar in the DocumentInteractionController View Controller consistent with the appearance of the navigation bar throughout the entire app (or at least visible!).
This line puts a transparent (or rather void) background image to your UINavigationBar. Why is that?
[[UINavigationBar appearance] setBackgroundImage:[[UIImage alloc] init] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
Just remove the line and everything works well.
If you want to set a shadow image, then you should think about using appearanceWhenContainedIn: instead of appearance so it won't spread to unhandled controllers.
As for the Status Bar Style, the simplest way would be to pass self.navigationController as the presenter, instead of self:
- (UIViewController *) documentInteractionControllerViewControllerForPreview: (UIDocumentInteractionController *) controller {
return self.navigationController;
}
Hope this will help,
i have a tab bar controller in witch i would like to embed a ABPeoplePickerNavigationController. I' done so by putting this code in viewDidLoad
[super viewDidLoad];
_addressBookController = [[ABPeoplePickerNavigationController alloc] init];
[_addressBookController setDelegate:self];
[_addressBookController setPeoplePickerDelegate:self];
[self.view addSubview:_addressBookController.view];
my problem is that i would like to uniform the ABPeople controller to my app bgcolor and tint, but actually i'm only able to change the title of the navigation controller via the method below
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated
can some help me to change all colors and tints?
Thanks in advice
You can change the style of the ABPeoplePickerNavigationController using the appearanceWhenContainedIn method (iOS > 5). Remember to do your customization before loading the view controller.
Here an example:
[[UINavigationBar appearanceWhenContainedIn:[ABPeoplePickerNavigationController class], nil] setBarTintColor:[UIColor yourColor]];
[[UIBarButtonItem appearanceWhenContainedIn:[ABPeoplePickerNavigationController class], nil] setTintColor:[UIColor yourColor]];
[[UINavigationBar appearanceWhenContainedIn:[ABPeoplePickerNavigationController class], nil] setTitleTextAttributes:#{NSForegroundColorAttributeName : [UIColor yourColor], NSFontAttributeName : [UIFont yourFont]}]; //navigation bar title
[[UISearchBar appearanceWhenContainedIn:[ABPeoplePickerNavigationController class], nil] setBarTintColor:[UIColor yourColor]];
[[UITableView appearanceWhenContainedIn:[ABPeoplePickerNavigationController class], nil] setSectionIndexColor:[UIColor yourColor]];
[[UITableViewHeaderFooterView appearanceWhenContainedIn:[ABPeoplePickerNavigationController class], nil] setTintColor:yourColor];
If you want a full list of what properties you can change, you can look at this question: What properties can I set via an UIAppearance proxy?
I'm doing some changes to the Navigationbar with appearance in appdelegate.
This is my method:
-(void) setAppearance{
NSMutableDictionary *titleBarAttributes = [NSMutableDictionary dictionaryWithDictionary: [[UINavigationBar appearance] titleTextAttributes]];
[titleBarAttributes setValue:[UIFont fontWithName:#"AvantGarde-ExtraLight" size:18] forKey:NSFontAttributeName];
[titleBarAttributes setValue:[UIColor whiteColor] forKey:NSForegroundColorAttributeName];
[[UINavigationBar appearance] setTitleTextAttributes:titleBarAttributes];
[[UINavigationBar appearance] setBarTintColor:[UIColor colorWithRed:6.0/256.0 green:57.0/256.0 blue:84.0/256.0 alpha:1.0]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
int borderSize = 3;
UIImageView *navBorder = [[UIImageView alloc] initWithFrame:CGRectMake(0,
41,
320,
borderSize)];
navBorder.image = [UIImage imageNamed:#"energy_line"];
navBorder.tag = 999;
[[UINavigationBar appearance] addSubview:navBorder];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
I have a method in my appdelegate that sets the window to my first viewController, when i call this method, my navBorder is removed from the navigationbar. I don't understand why this happens, there is no code that changes anything in my navigationbar in the viewcontroller.
- (void)rootView
{
[self.window setRootViewController:initialViewController];
}
I answered pretty much the same question here: https://stackoverflow.com/a/26414437/538491
But here is a summary:
Calling [[UINavigationBar appearance] returns an appearance proxy for the receiver class. The addSubview: method is not tagged as UI_APPEARANCE_SELECTOR. One major downside to UIAppearance's proxy approach is that it's difficult to know which selectors are compatible.
You should get a hold of the navigation bar and add the image there by calling this method: [self.navigationController.navigationBar addSubview:navBorder] or you should subclass UINavigationBar which gives you more flexibility.
I have this code in my App Delegate:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"Nav Bar.png"] forBarMetrics:UIBarMetricsDefault];
This works great, but I use the MFMailComposeViewController and I want it to have the default NavigationBar appearance.
How do I do that?
EDIT:
I tried this code:
[[UINavigationBar appearanceWhenContainedIn: [MFMailComposeViewController class], [UIViewController class], nil] setBackgroundImage:[UIImage imageNamed:#"Textured Background.png"] forBarMetrics:UIBarMetricsDefault];
I've also tried having only this code. Nothing changes. Default Nav bar, including with the Mail View Controller.
I think it could be something with the appearanceWhenContainedIn:. Does anyone know what MFMailComposeViewController would be contained in?
I figured it out! Here's the code:
[[UINavigationBar appearance] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];
MFMailComposeViewController *emailVC = [[MFMailComposeViewController alloc] init];
//the rest of the implementation goes here...
[self presentViewController:emailVC animated:YES completion:nil];
Then, I set the nav bar appearance back to normal here:
- (void)mailComposeController:(MFMailComposeViewController*)controller didFinishWithResult:(MFMailComposeResult)result error:(NSError*)error
{
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"Nav Bar.png"] forBarMetrics:UIBarMetricsDefault];
[self dismissViewControllerAnimated:YES completion:nil];
}
You can try this:
[UINavigationBar appearanceWhenContainedIn: [MFMailComposeViewController class], nil]
Which means all navigation bars contained in a MFMailComposeViewController class
From the docs: UIAppearance
This will return the appearance proxy so you can modify it like this:
[[UINavigationBar appearanceWhenContainedIn: [MFMailComposeViewController class], nil] setBackgroundImage:myImage];
Hope that helps.