ios7 setBackButtonBackgroundImage image is still stretched - ios

Using the following code to set a global navigation back button image:
float imageSize = 21.5; // #2x is 43px width
UIImage *barBackBtnImg = [[UIImage imageNamed:#"arrow-back-white"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, imageSize, 0, 0)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:barBackBtnImg
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)
forBarMetrics:UIBarMetricsDefault];
Original image: http://cl.ly/XJgD and
in-app (being stretched): http://cl.ly/XKc0
Any ideas why the image is still being stretched?

If anyone is interested, this was my fix:
[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:#"arrow-back-white"]];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:[UIImage imageNamed:#"arrow-back-white"]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

Related

iOS set default back button appearance

I want to set a default behaviour for the navigation bar's back button, so it will look the same throughout the app. I also want to remove the default text, which I have already figured out.
I have tried the following without success:
[[UINavigationBar appearance] setBackIndicatorImage:[UIImage imageNamed:#"icon_backarrow"]];
//set default back text to #""
You should use UIBarButtonItem
UIImage *backButtonImage = [[UIImage imageNamed:#"icon_backarrow"]
resizableImageWithCapInsets:UIEdgeInsetsMake(4, 5, 4, 5)];
// Back button nav bar items
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage
forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage
forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage
forState:UIControlStateSelected barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-2.0f, 1.0f)
forBarMetrics:UIBarMetricsDefault];

Change colour of arrow in Back Button iOS

I'm trying to change the colour of the arrow for the back button in the navigation bar. I've been able to change the text colour, but not the arrow. Here is my code to change the text colour:
[[UIBarButtonItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:
[UIColor whiteColor], UITextAttributeTextColor,
nil] forState:UIControlStateNormal];
If anyone could advise me on how to change the arrow coliur, that would be very helpful!
You can use images like this to change the background of back button:
UIImage *buttonBack30 = [[UIImage imageNamed:#"button_back_textured_30"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 13, 0, 5)];
UIImage *buttonBack24 = [[UIImage imageNamed:#"button_back_textured_24"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 12, 0, 5)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonBack30
forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonBack24
forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone];
Source: RAYWENDERLICH
If you don't want to use images, you can change the tintcolor of navigation bar, because it determines the color of text of bar button item:
[[UINavigationBar appearance] setTintColor:[UIColor yourColor]];

iOS: UIToolbar setBackgroundImage not working

I can not change the uitoolbar background image. gives error.
This navigationBar code is working.
UIImage *navBackgroundImage = [UIImage imageNamed:#"bartop.png"];
[[UINavigationBar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];
But this toolbar code is not working and gives error.
UIImage *navBackgroundImage = [UIImage imageNamed:#"bartop.png"];
[[UIToolbar appearance] setBackgroundImage:navBackgroundImage forBarMetrics:UIBarMetricsDefault];
Where is my wrong?
UPDATE:
This code is working:
UIImage *testimage = [[UIImage imageNamed:#"bartop"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UIToolbar appearance] setBackgroundImage:testimage forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsDefault];
[[UIToolbar appearance] setBackgroundImage:testimage forToolbarPosition:UIToolbarPositionAny barMetrics:UIBarMetricsLandscapePhone];
According to the documentation, the method you need to use with UIToolbar is
- setBackgroundImage:(UIImage *)backgroundImage forToolbarPosition:(UIToolbarPosition)topOrBottom barMetrics:(UIBarMetrics)barMetrics
You are using
- setBackgroundImage:(UIImage *)backgroundImage forBarMetrics:(UIBarMetrics)barMetrics
Try using that and see if it works for you.
More info here.

IOS Custom UIBarbuttonItem change position in detail view

I'm trying to customize my navigationbar's UIBarbuttonItem so that I'm using this im my Appdelegate.m
// didFinishLaunchingWithOptions:
{
UIImage *navBarImage = [UIImage imageNamed:#"nav-bar.png"];
[[UINavigationBar appearance] setBackgroundImage:navBarImage
forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setTitleVerticalPositionAdjustment:5
forBarMetrics:UIBarMetricsDefault];
UIImage *barButtonSave = [[UIImage imageNamed:#"nav-bar-button.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 2, 0, 2)];
[[UIBarButtonItem appearance] setBackgroundImage:barButtonSave
forState:UIControlStateNormal
style:UIBarButtonItemStyleDone
barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackgroundVerticalPositionAdjustment:5 forBarMetrics:UIBarMetricsDefault];
return YES;
}
When I'm done with this I just place a UIBarbuttonItem with Storyboard and I'm done.
The point is I noticed that the "Save" button changes between my views!
It looks like is moving down few pixels in my DetailView:
Why is That?
I still don't know why. but I solved giving my custom UIbarbuttonItem image the 30px default height.
[see similar issue UIBarButtonItem shifting downwards after a UINavigationController push

How to customize UINavigationBar in IOS5

In IOS5, I do not yet know how to customize UINavigationBar.
My code is like this:
[[UINavigationBar appearance] setBackgroundColor:[UIColor colorWithWhite:0.5f alpha:1.0]];
[[UINavigationBar appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys: [UIColor blackColor],UITextAttributeTextColor
,[UIColor blackColor], UITextAttributeTextShadowColor
,[NSValue valueWithUIOffset:UIOffsetMake(0, 0)], UITextAttributeTextShadowOffset
,[UIFont fontWithName:#"Arial" size:20.0],UITextAttributeFont
, nil]];
// Customize UIBarButtonItems
UIImage *gradientImage44 = [[UIImage imageNamed: #"title__bg.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UINavigationBar appearance] setBackgroundImage:gradientImage44 forBarMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor],UITextAttributeTextColor
,[UIColor whiteColor], UITextAttributeTextShadowColor
,[NSValue valueWithUIOffset:UIOffsetMake(0, 0)], UITextAttributeTextShadowOffset
,[UIFont fontWithName:#"Arial" size:14.0],UITextAttributeFont
, nil] forState:UIControlStateNormal];
// Customize back button items differently
UIImage *buttonBack30 = [[UIImage imageNamed:#"bn_back"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 13, 0, 5)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonBack30 forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
This pic is UINavigationViewController used in PopoverView.
This pic is UINavigationViewController opened by Modal.
As you see, I set background-image, nevertheless NavigationBar's border is different.
Is this a problem about PopoverView?
I do not know What I'd missed.
Please tell me your advice. Thanks!!! and Happy new year!!!
Goto AppDelegate.m and paste the code under
- (BOOL)application:(UIApplication *)application
didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
Set the status bar to black color.
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque
animated:NO];
Change #"menubar.png" to the file name of your image.
UIImage *navBar = [UIImage imageNamed:#"menubar.png"];
[[UINavigationBar appearance] setBackgroundImage:navBar
forBarMetrics:UIBarMetricsDefault];
Have a look at this: UINavigationBar Apple developer reference

Resources