2017-09-25 349 views
-1

How to set Left/Right and title view (OBJC)iOS的11導航欄圖標問題

iOS的11導航問題,我需要設置導航欄

  1. 這是我當前的代碼左右和標題視圖。
  2. 原來是這樣,但現在我有問題吧:

    btnMenu = [UIButton buttonWithType:UIButtonTypeSystem]; 
        [btnMenu setFrame:CGRectMake(0, 0, 25, 25)]; 
        [btnMenu setTintColor:[UIColor blackColor]]; 
        [btnMenu setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft]; 
        [btnMenu setImage:[UIImage imageNamed:@"menu"] forState:UIControlStateNormal]; 
        [btnMenu addTarget:self action:@selector(clickOnMenu:) forControlEvents:UIControlEventTouchUpInside]; 
    
        leftBarButton2 = [[UIBarButtonItem alloc] initWithCustomView:btnMenu]; 
    
        [arrLeftBarButton addObject:leftBarButton2]; 
    
    self.navigationItem.leftBarButtonItems = [NSArray arrayWithArray:arrLeftBarButton]; 
    
    
    [viewTitle addSubview:search]; 
    [viewTitle addSubview:btnSelectSearch]; 
    viewTitle.translatesAutoresizingMaskIntoConstraints = false; 
    
    self.navigationItem.titleView = viewTitle; 
    
    BBBadgeBarButtonItem *badgeNotify = [[BBBadgeBarButtonItem alloc] initWithCustomUIButton:btnNotify]; 
    badgeNotify.badgeBGColor = [UIColor whiteColor]; 
    badgeNotify.badgeTextColor = [UIColor blackColor]; 
    badgeNotify.badgeValue = @"0"; 
    
    self.navigationItem.rightBarButtonItem = badgeNotify; 
    
+0

看到https://開頭計算器.com/questions/44442573/navigation-bar-rightbaritem-image-button-bug-ios-11 –

+0

It似乎您正在設置導航欄不是建議大小的圖像。查看人機界面指南:https://developer.apple.com/ios/human-interface-guidelines/icons-and-images/custom-icons/ PS:如果您可以發佈您的代碼,我們會更容易。所以可以指出實際問題。 – Rishi

回答

0

對象 -

NSLayoutConstraint * widthConstraint = [btnMenu.widthAnchor constraintEqualToConstant:25]; 
NSLayoutConstraint * heightConstraint =[btnMenu.heightAnchor constraintEqualToConstant:25]; 
[widthConstraint setActive:YES]; 
[heightConstraint setActive:YES]; 

UIBarButtonItem* btnMenuItem = [[UIBarButtonItem alloc] initWithCustomView: btnMenu]; 
self.navigationItem.leftBarButtonItem = btnMenuItem; 

斯威夫特

let widthConstraint = button.widthAnchor.constraint(equalToConstant: 25) 
let heightConstraint = button.heightAnchor.constraint(equalToConstant: 25) 
heightConstraint.isActive = true 
widthConstraint.isActive = true