0

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

enter image description here

But, In Version iOS 11 its color and size have been improper.

enter image description here

Please provide proper solution to resolve this issue.

I have tried Tint Color also, but it doesn't work.

yashica15
  • 53
  • 13

2 Answers2

0

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;
BuLB JoBs
  • 841
  • 4
  • 20
0

// 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];
    }
}
Damo
  • 12,840
  • 3
  • 51
  • 62