M.Masa
M.Masa

Reputation: 542

BarButtonItem on NavigationBar is forced to be transparent if returned with popViewController

I have a problem about UIBarButtonItem on NavigationBar.

  1. Transit from FirstViewController to SeconderViewController by pusuViewController.
  2. Return to FirstViewController with return button on left side of NavigationBar.
  3. [Problem happen] The Color of [next] button on right side of NavigationBar is transparent.

(You can tap [next] button althought the color is transparent )

This problem happen on iPhone8(iOS11.2.1(15C153), not heppen on iPhone6(iOS10.3.3(14G60)).

enter image description here

My code is below,

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];
    self.window.backgroundColor = UIColor.blackColor;

    UIViewController *vc = [[FirstViewController alloc] init];
    UINavigationController *nc = [[UINavigationController alloc] initWithRootViewController:vc];
    self.window.rootViewController = nc;
    [self.window makeKeyAndVisible];

    return YES;
}

FirstViewContrtoller.m

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.navigationItem.title = @"First View";
    UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"next", nil)
                                                      style:UIBarButtonItemStylePlain
                                                     target:self
                                                     action:@selector(touchUpNextButton:)];
    self.navigationItem.rightBarButtonItem = nextButton;
}

- (void)touchUpNextButton:(id)sender
{
    UIViewController *vc = [[SecondViewController alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

SecondViewController.m

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view.

    self.navigationItem.title = @"Second View";
}

I'd appreciate if you would provide me a good solution.

Thank you.

Upvotes: 0

Views: 130

Answers (1)

motbantuangiauten
motbantuangiauten

Reputation: 151

I think it is the bugs of iOS 11.2.1 You can temporary fix by following solution:

UIBarButtonItem *nextButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"next", nil)
                                                      style:UIBarButtonItemStylePlain
                                                     target:self
                                                     action:@selector(touchUpNextButton:)];
[nextButton setTitleTextAttributes:@{NSForegroundColorAttributeName : [self.view tintColor], NSFontAttributeName:[UIFont systemFontOfSize:16.9f]} forState:UIControlStateNormal];

Hope that can help you.

Upvotes: 1

Related Questions