简体   繁体   中英

iOS 11 Navigationbar icon issue

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

iOS 11 navigation issue i need to set left right and title view on navigation bar

  1. This is My current code.
  2. So is this, but now i have issue with it:

     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;

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

Swift

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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