UINavigationBar Back button duplicates twice - ios

I have used the following code in my appDelegate and customizing back bar button goes well. When i used segue for the controllers navigation backbarbutton appears twice.
UIImage *buttonPortait = [[UIImage imageNamed:#"back-icon"]
resizableImageWithCapInsets:UIEdgeInsetsMake(0,0, 0,0)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:buttonPortait
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
[UIBarButtonItem.appearance setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -64) forBarMetrics:UIBarMetricsDefault];
I also used navigationBar setTranslucent:NO but yet the problem surviving. Any solution for this problem. Thanks in advance.

I got the solution by altering the image size for the back bar button.
I used image size with height 30x(non-retina)/60x(retina) and width 90x(non-retina)/180x(retina)
cheers!!!

Related

xcode remove custom navigation image in pickerview galley

I added the following code in the appDelegate to achieve custom background images for the navigation bar.
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"Nav-Bar_01.png"] forBarMetrics:UIBarMetricsDefault];
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"Nav-Bar_02_alter.png"] forBarMetrics:UIBarMetricsDefaultPrompt];
However, I want to exclude the native gallery pickerView from this background.
Is there any way to do so without applying the background on each navigation bar alone, but keeping the same code in the appDelegate ?
I ended up placing a background image for every navigation controller instead of placing it in the App Delegate. The background was then not applied on the pickerView.
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"Nav-Bar_01"] forBarMetrics:UIBarMetricsDefault];

Back button strangely disappearing in UINavigationController but keeps working

Under iOS7 I've been experiencing an issue where the back button item will not show up if it has been set with a specific background image:
int imageSize = 21; //REPLACE WITH YOUR IMAGE WIDTH
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(-400.f, 0)
forBarMetrics:UIBarMetricsDefault];
UIImage *barBackBtnImg = [[UIImage imageNamed:#"BackArrowDark.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, imageSize, 0, 0)];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:barBackBtnImg
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];
Upon doing this, any ViewController that I push in the navigation controller will have no back button item appearing, even though pressing where it should be, will make it appear, and any subsequent pushes of this view controller will have the button present on the screen.
This issue is only appearing under iOS7: everything works perfectly under iOS6.
Changing the back button completely with a leftBarButtonItem disables the back swipe, so that is not an option.
Any idea what I am doing wrong?
Thanks much for your consideration.
After trying different solutions, I found that changing the backIndicatorImage works best under iOS7, and it seems to be in line with the iOS7 interface paradigm:
[[UINavigationBar appearance] setTintColor:[UIColor grayColor]];
[[UIBarButtonItem appearance] setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60) forBarMetrics:UIBarMetricsDefault]; // Takes out title
UIImage *backButtonImage = [UIImage imageNamed:#"BackArrowDark.png"];
if ([UINavigationBar instancesRespondToSelector:#selector(setBackIndicatorImage:)]) {
[[UINavigationBar appearance] setBackIndicatorImage:backButtonImage];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:backButtonImage];
} else {
int imageSize = 21; // REPLACE WITH YOUR IMAGE WIDTH
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:[backButtonImage resizableImageWithCapInsets:UIEdgeInsetsMake(0, imageSize, 0, 0)] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
}
With this method:
When going back in the navigation controller, the back button item transition is the same as with the default indicator (a departure from the back button sliding away as well under iOS6);
Under iOS6, the backButton is changed and keeps its default iOS6 behaviour.
I'm happy!
Make sure you are not calling this in the view controller:
self.navigationController.navigationBar.tintColor = [UIColor redColor];
In iOS 7, this will tint the navigation bar but will also make your buttons invisible, yet functional just as you are describing.

Issued changing the navigationbar image?

Currently, I am able to change the tint of the my UINavigationBar by
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:74/255.0f green:74/255.0f blue:74/255.0f alpha:1.0f];
However when I try to implement the following code to change the image of the UINavigationBar all together, I see no results..
UIImage *navImageBackground = [[UIImage imageNamed:#"texturedNav"] //This being my .png image
resizableImageWithCapInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
[[UINavigationBar appearance] setBackgroundImage:navImageBackground
forBarMetrics:UIBarMetricsDefault];
What am I doing wrong here?
You're probably calling the appearance delegate after the navigation bar is already on screen so your request is being 'ignored'. Or, at least, not causing a UI update.
Set the appearance before the navigation bar is shown. Or, force a UI refresh by hiding and showing the navigation bar (without animation).

UINavigationController background color changes that hide Back Button in iOS

Now I am trying to change UINavigationController background image with my custom Image.
I can change with following codes.
[navigation.navigationBar insertSubview:[[UIImageView alloc] initWithImage:[UIImage imageNamed:#"navController.png"]] atIndex:1];
So I got following pic. That pic is right and show the BarButton.
But when I go to the detailViewController , there is no BackButton. However I can tap without seeing it.
After I back to MainViewController , my UINavigationController Background is happening like following pic.
They are hiding my button. I'm thinking atIndex:1 is making this problem because Index 1 is above 0 and All button Index must be 0.
That's why all buttons are disappearing.
So how can I solve that problem? Please help.
Thanks for your help.
// not supported on iOS4
UINavigationBar *navBar = [purchaseNavController navigationBar];
if ([navBar respondsToSelector:#selector(setBackgroundImage:forBarMetrics:)])
{
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"brnlthr_nav.jpg"] forBarMetrics:UIBarMetricsDefault];
}
Try using the appearance proxy provided by apple
[[UINavigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"your_image"] forBarMetrics:UIBarMetricsDefault];
that will set it for the entire application or you can use
[[self.navigationController.navigationBar appearance] setBackgroundImage:[UIImage imageNamed:#"your_image"]];

Remove UIBarButtonItem image

I have a UIBarButtonItem that I originally change the background image to. But I would like to be able to change the same UIBarButtonItem back to a default looking one (specifically a done button). Then again back to the way it was prior to (that shouldn't be a problem).
Here is how I change the appearance at first:
[menuButton setBackButtonBackgroundImage:[UIImage imageNamed:#"menuButton.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
Then back I was trying things like:
menuButton.style = UIBarButtonItemStyleDone;
menuButton.title = #"Done";
//the above didn't do anything, so I tried to make my own image to
//replace the first image. But below did't do anything either.
[menuButton setBackButtonBackgroundImage:[UIImage imageNamed:#"doneButton.png"] forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
Use setBackgroundImage:... instead of setBackButtonBackgroundImage:..., you're only setting the appearance of back buttons (in navigation bars).

Resources