iOS 7 Custom Back Button

Custom image for UINavigation Back Button in iOS 7

Try to set UIBarButtonItem like this way in ios7:-

UIImage *temp = [[UIImage imageNamed:@"theImage"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];    
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithImage:temp style:UIBarButtonItemStyleBordered target:self action:@selector(action)];

Here is an original post in apple Dev center discussion Forums

For supporting both version iOS7 as well as lower then you check system-version and set code like:-

UIImage *temp=nil;

if([[[UIDevice currentDevice] systemVersion] floatValue] < 7.0)
{
temp = [UIImage imageNamed:@"btn-back.png"];
}
else
{
temp = [[UIImage imageNamed:@"btn-back.png"] imageWithRenderingMode: UIImageRenderingModeAlwaysOriginal];
}

How to create a custom mask image for back buttons in iOS7

i think this is what you are looking for

self.navigationController.navigationBar.backIndicatorImage = [UIImage yourImage];
self.navigationController.navigationBar.backIndicatorTransitionMaskImage = [UIImage yourImage];

iOS 7: Custom Back Indicator Image Position

That happens because you are just changing the image source of the Back Indicator in your UINavigationView, and not the frame as well.
See, when the UINavigationView is created, the Back Indicator's frame is set to hold the size of the default iOS 7 back button image. The default back button image is bigger than yours, and that's why it looks not aligned.

To fix that you have to reset the Back Indicator's Frame to hold the size of your image. Another option is to create a UIButton with the right frame size and image and assign to a UIBarButtonItem. Then you can replace the backBarButtonItem from your UINavigationItem with the new UIBarButtonItem you created.

iOS 7 Back Button Pop Gesture

Just add the following line of code:

[self.navigationController.interactivePopGestureRecognizer addTarget:self action:@selector(handleGesture:)];

You can add your own UIGestureRecognizer and pop the UIViewController yourself. See the docs for further info.

Changing back button in iOS 7 disables swipe to navigate back

IMPORTANT:
This is a hack. I would recommend taking a look at this answer.

Calling the following line after assigning the leftBarButtonItem worked for me:

self.navigationController.interactivePopGestureRecognizer.delegate = self;

Edit:
This does not work if called in init methods. It should be called in viewDidLoad or similar methods.

iOS 7 UIBarButton back button arrow color

To change the back button chevron color for a specific navigation controller*:

self.navigationController.navigationBar.tintColor = [UIColor whiteColor];

*If you are using an app with more than 1 navigation controller, and you want this chevron color to apply to each, you may want to use the appearance proxy to set the back button chevron for every navigation controller, as follows:

[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];

And for good measure, in swift (thanks to Jay Mayu in the comments):

UINavigationBar.appearance().tintColor = UIColor.whiteColor()


Related Topics



Leave a reply



Submit