iOS的11导航栏图标问题

iOS的11导航栏图标问题

问题描述:

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

对象 -

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