UINavigationBar setBackgroundImageForBarMetrics doesn't work in iOS 7 - iphone

i'm trying to se an image for the background of the navigation bar, and i'm doing this like i do in iOS6:
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"Navbar.png"] forBarMetrics:UIBarMetricsDefault];
this is the image:
and this is the result when i run:
on iOS 6 works perfect, instead on iOS 7 have that problem...

Try to add this to your navigation Controller:
self.navigationController.navigationBar.tintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"Navbar.png"]];

Related

Custom UITabBar Background image

I Have this Image for my UITabBar:
And this is how i add it to the Tab:
[[UITabBar appearance] setBackgroundImage:[UIImage imageNamed:#"NewTabBar.png"]];
[[UITabBar appearance] setSelectionIndicatorImage:[UIImage imageNamed:#"tabbar_selection.png"]];
And i noticed that when i rotate the device to landscape mode the image won't re-size to all the screen.
How i can re-size it?
Try to incorporate resizableimageWithCapInsets:, like this:
[[UITabBar appearance] setSelectionIndicatorImage:[[UIImage imageNamed:#"tabbar_selection.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(5, 5, 5, 5)]];
Try to
self.tabBarController.tabBar.autoresizingMask=UIViewAutoresizingFlexibleRightMargin || UIViewAutoresizingFlexibleLeftMargin;
Or experiment with it;

Navigation bar image black

In my application i add custom navigation image while adding the remaining part of the image shows black in color, i used following code,
UIImage *image = [UIImage imageNamed: #"navbar.png"];
[self.navigationController.navigationBar setBackgroundImage:image forBarMetrics:UIBarStyleDefault];
i want to show the back ground color in the in the black color part.what should change in code?
Please Try Following may be it works fine.
UINavigationBar *navBar = [[self navigationController] navigationBar];
UIImage *backgroundImage = [UIImage imageNamed:#"navbar.png"];
[navBar setBackgroundImage:backgroundImage forBarMetrics:UIBarMetricsDefault];
Edited
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"navbar.png"] forBarMetrics:UIBarMetricsDefault];
self.navigationController.navigationBar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:#"navbar.png"]];
I'm using very useful library (class SCNavigationBar) for styling navigaitonBar, download it here
It supports all orientations, it works with no problem in my many apps.

UIToolbar shows different color on ios 5.0 and ios 6.0 Simulators

I have set tintcolor for my UIToolBar.It displays Correctly in ios 6.0 but it shows black color on ios 5.0 simulator. My code is here
originalBounds = mysearchBarBarItem.customView.bounds;
mySearchBar.bounds = CGRectMake(0,0,215,44);
myTopToolbar.tintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:NAVIGATION_BAR_BACKGROUND]];
myTopToolbar.barStyle = UIBarStyleDefault;
mySearchBar.barStyle = UIBarStyleDefault;
mySearchBar.tintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:NAVIGATION_BAR_BACKGROUND]];
[myTopToolbar setItems:toolBarItemsArray animated:YES];
I don't know if this can make a difference, but you could try to change the order in which you assign the style and color of the bar. Try:
myTopToolbar.barStyle = UIBarStyleDefault;
myTopToolbar.tintColor = [UIColor colorWithPatternImage:[UIImage imageNamed:NAVIGATION_BAR_BACKGROUND]];
It's possible that assigning the style after changing the tintcolor resets the color.
EDIT
Why this would affect only ios5 and not ios6 I don't know.
You can use UIAppearance (for iOS 5.0 and above) .
Try to set color property
myTopToolbar.tintColor = [UIColor redColor];
If this works fine in both iOS6 and iOS5, then problem should be in image.
Edited
Check this question
iphone:UIToolbar when set to tint color behaves differently on iOS 5 and ios6 simulator?
Try to do this in your app delegate implementation class this will change the toolBar and searchBar color throughout the application
for setting tint of searchbar
[[UISearchBar appearance] setTintColor:[UIColor colorWithPatternImage:[UIImage imageNamed:NAVIGATION_BAR_BACKGROUND]]];
OR
[[UISearchBar appearance] setTintColor:[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1]];
for setting tint of toolbar
[[UIToolbar appearance] setTintColor:[UIColor colorWithPatternImage:[UIImage imageNamed:NAVIGATION_BAR_BACKGROUND]];
OR
[[UIToolbar appearance] setTintColor:[UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1]];
for setting background image
[[UIToolbar appearance] setBackgroundImage:[UIImage imageNamed:#"bgtoolbar.png"] forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
I have solveed It. just converted the Image to RGB Values and set like this.
myTopToolbar.tintColor = [UIColor colorWithRed:139/256.0 green:0/256.0 blue:0/256.0 alpha:1.0];

MPMoviePlayerViewController vs. Appearance-Framework (iOS 5)

i am using a MPMoviePlayerViewController inside my Project. I have defined the following appearance for UIButtons and UINavigationbar like so:
[[UIBarButtonItem appearanceWhenContainedIn:[UINavigationBar class], nil]
setBackgroundImage:[UIImage imageNamed:#"woodenBarButton"]
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"navigationbarBackground"]
forBarMetrics:UIBarMetricsDefault];
So now MPMoviePlayerViewController is also using a navigation bar. The problem is now: The button uses the given appearance but the toolbar not => it looks crappy. So now i have the following questions:
Can i convince the UINavigationBar in MPMoviePlayerViewController to use the appearance?
OR can is remove appearance completely only for the MPMoviePlayerViewController.
I tried to access the button via playerViewController.navigationitem.leftbarbuttonitem and overwrite properties but that doesn't work.
Would be great if you can help me. Thanks.
have you tried also setting appearanceWhenContainedIn for MPMoviePlayerViewController? appearance and appearanceWhenContainedIn works both at the same time.
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"navigationbarBackground"]
forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearanceWhenContainedIn:[MPMoviePlayerViewController class], nil] setBackgroundImage:nil forBarMetrics:UIBarMetricsDefault];

clear background image for navigationbar IOS 5 and 4

I am going to have different background image for navigation bar.(e.g.:when it is pushed)
i use this code
if([self respondsToSelector: #selector( presentingViewController)]){
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"sectionImage_iphone.png"] forBarMetrics:UIBarMetricsDefault];
}else{
[self.navigationController.navigationBar.layer.contents removeFromSuperlayer];
self.navigationController.navigationBar.layer.contents = (id)[UIImage imageNamed:#"sectionImage_iphone.png"].CGImage;
}
If i call it again does the background image is replaced or stacked? if stacked, how to remove it?(for ios 4 and 5)
Thank You