I am facing issue in iOS 11 with custom BackButton Image color.
BackButton Image works correct in versions lower the iOS 11.
I have customized the Back Button Image of UINavigationBar
by using following code.
[[UINavigationBar appearance] setBackgroundColor:[UIColor blackColor]];
[[UINavigationBar appearance] setBarTintColor:[UIColor blackColor]];
[[UINavigationBar appearance] setTintColor:[UIColor whiteColor]];
[[UINavigationBar appearance] setTranslucent:false];
UIEdgeInsets insets = UIEdgeInsetsMake(0, 0, 5.0f, 0);
UIImage *backArrowImage = [[UIImage imageNamed:@"icon_nav_back"] imageWithAlignmentRectInsets:insets];
[[UINavigationBar appearance] setBackIndicatorImage:backArrowImage];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:backArrowImage];
It displays a proper image with default color of image in versions lower than iOS11
But, In Version iOS 11 its color and size have been improper.
Please provide proper solution to resolve this issue.
I have tried Tint Color also, but it doesn't work.
Follow this link: Swift how to change tintColor of backIndicatorImage
set image on this method setBackIndicatorTransitionMaskImage
Might be help!
[UINavigationBar appearance].translucent = NO;
[[UINavigationBar appearance] setBackIndicatorImage:backArrowImage];
[[UINavigationBar appearance] setBackIndicatorTransitionMaskImage:backArrowImage];
Updated use following code it's definitely set back image
UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[backBtn setBackgroundImage:backArrowImage forState:UIControlStateNormal];
[backBtn addTarget:self action:@selector(goback) forControlEvents:UIControlEventTouchUpInside];
backBtn.frame = CGRectMake(0, 0, 54, 30);
UIBarButtonItem *backButton = [[UIBarButtonItem alloc] initWithCustomView:backBtn] ;
self.navigationItem.leftBarButtonItem = backButton;
// untested code
// try to see if you can access the back button directly
NSArray *leftBarButtonItems = self.navigationController.navigationBar.items.firstObject.leftBarButtonItems;
for (id barButtonItem in leftBarButtonItems) {
UIBarButtonItem *item = (UIBarButtonItem*)barButtonItem;
if (item) {
item.tintColor = [UIColor whiteColor];
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.