2017-09-26 505 views
0

我們使用下面的代碼在iOS 10 SDK和XCode 8的導航欄中顯示leftbarbutton項目,但是當我們更新到xcode9和ios 11 sdk時。左欄按鈕項目不顯示。我通過網絡搜索,但無法找到任何解決方案。 有誰知道任何答案?IOS 11導航欄按鈕項目

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

,你可以找到以下

enter image description here

+0

嘗試把'loginViewController.navigationItem.leftBarButtonItem = cancelButton;''後= navigationController.viewControllers @ loginViewController]'或者只是之前'present..' – Sti

+0

沒有工作也 – tolgatanriverdi

+0

@tolgatanriverdi你可以發佈一個小項目,會證明這個問題? – Bannings

回答

0

結果在IOS 11檢查下面的例子

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

沒有工作 – tolgatanriverdi

0

當你設置「cancelButton.tintColor它不工作= [ UIColor whiteColor]'在ios11中。你可以使用方法「setTitleTextAttributes」。