繁体   English   中英

iOS 11 导航栏图标问题

[英]iOS 11 Navigationbar icon issue

如何设置左/右和标题视图 (OBJC)

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;

对象-C

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM