如果与 popViewController 一起返回,NavigationBar 上的 BarButtonItem 将被强制透明
BarButtonItem on NavigationBar is forced to be transparent if returned with popViewController
我对 NavigationBar 上的 UIBarButtonItem 有疑问。
- 通过 pusuViewController 从 FirstViewController 传输到 SeconderViewController。
- Return 到导航栏左侧带有 return 按钮的 FirstViewController。
- [问题发生] NavigationBar右侧的[next]按钮颜色是透明的
(虽然颜色是透明的,但您可以点击[下一步]按钮)
此问题发生在 iPhone8(iOS11.2.1(15C153),而不是 iPhone6(iOS10.3.3(14G60)).
我的代码如下,
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";
}
如果你能给我一个好的解决方案,我将不胜感激。
谢谢。
我认为这是 iOS 11.2.1 的错误
您可以通过以下解决方案临时修复:
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];
希望对你有所帮助。
我对 NavigationBar 上的 UIBarButtonItem 有疑问。
- 通过 pusuViewController 从 FirstViewController 传输到 SeconderViewController。
- Return 到导航栏左侧带有 return 按钮的 FirstViewController。
- [问题发生] NavigationBar右侧的[next]按钮颜色是透明的
(虽然颜色是透明的,但您可以点击[下一步]按钮)
此问题发生在 iPhone8(iOS11.2.1(15C153),而不是 iPhone6(iOS10.3.3(14G60)).
我的代码如下,
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";
}
如果你能给我一个好的解决方案,我将不胜感激。
谢谢。
我认为这是 iOS 11.2.1 的错误 您可以通过以下解决方案临时修复:
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];
希望对你有所帮助。