Reputation: 542
I have a problem about UIBarButtonItem on NavigationBar.
(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)).
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
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