IOS 11导航栏按钮项

时间:2017-09-26 15:17:38

标签: ios objective-c ios11

我们使用下面的代码在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中找到结果

enter image description here

2 个答案:

答案 0 :(得分:0)

检查以下示例

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];

答案 1 :(得分:0)

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