【发布时间】:2017-09-26 15:17:38
【问题描述】:
我们使用下面的代码在 IOS 10 SDK 和 XCode 8 的导航栏中显示 leftbarbutton 项目,但是当我们更新到 xcode9 和 ios 11 sdk 时。左侧栏按钮项目不显示。我通过网络搜索,但找不到任何解决方案。 有谁知道答案吗?
UIBarButtonItem *cancelButton = nil;
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"11")) {
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 35, 35)];
//button.imageEdgeInsets = UIEdgeInsetsMake(0, -15, 0, 15);
//button.contentEdgeInsets = UIEdgeInsetsMake(13, 8, 13, 8);
NSLayoutConstraint *widthConst = [button.widthAnchor constraintEqualToConstant:32.0];
NSLayoutConstraint *heightConst = [button.heightAnchor constraintEqualToConstant:32.0];
[button setImage:[UIImage imageNamed:@"cross"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(hide) forControlEvents:UIControlEventTouchUpInside];
cancelButton = [[UIBarButtonItem alloc] initWithCustomView:button];
widthConst.active = YES;
heightConst.active = YES;
} else {
cancelButton = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"cross"] style:UIBarButtonItemStylePlain target:loginRouter action:@selector(hide)];
}
cancelButton.tintColor = [UIColor whiteColor];
loginViewController.navigationItem.leftBarButtonItem = cancelButton;
loginRouter.loginViewController = loginViewController;
CardNavigationController *navigationController = [CardNavigationController darkBlueNavigationControllerWithClient:client];
navigationController.viewControllers = @[ loginViewController ];
navigationController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[onViewController presentViewController:navigationController animated:YES completion:nil];
你可以在下面的 ios 11 中找到结果
【问题讨论】:
-
尝试将
loginViewController.navigationItem.leftBarButtonItem = cancelButton;放在navigationController.viewControllers = @[ loginViewController ];之后或present..之前 -
那也没用
-
@tolgatanriverdi 你能发一个小项目来证明这个问题吗?
-
仍然找不到任何解决方案有人知道这个问题吗?
-
你解决了吗?
标签: ios objective-c ios11