【问题标题】:IOS 11 Navigation Bar Button ItemIOS 11 导航栏按钮项
【发布时间】: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


【解决方案1】:

检查以下示例

UIImage *imgCart = [self imageWithImage:[UIImage imageNamed:@"ic_cart"] scaledToSize:CGSizeMake(35, 35)] ;

imgCart = [_utils changeColorOf:imgCart to:[UIColor whiteColor]];
UIButton *btnCart = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)];
[btnCart addTarget:self action:@selector(btnCartClicked:) forControlEvents:UIControlEventTouchUpInside];
[btnCart setBackgroundImage:imgCart forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btnCart];

【讨论】:

    【解决方案2】:

    在 ios11 中设置 'cancelButton.tintColor = [UIColor whiteColor]' 时不起作用。您可以使用“setTitleTextAttributes”方法。

    【讨论】:

      猜你喜欢
      • 2017-11-10
      • 1970-01-01
      • 1970-01-01
      • 2018-03-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多