-1

How to set Left/Right and title view (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;
    
chirag bhalara
  • 203
  • 1
  • 10
  • see this https://stackoverflow.com/questions/44442573/navigation-bar-rightbaritem-image-button-bug-ios-11 – Anbu.Karthik Sep 25 '17 at 09:52
  • It seems that you are setting images which are not of recommended size for the navigation bar. Have look at the Human Interface Guidelines : https://developer.apple.com/ios/human-interface-guidelines/icons-and-images/custom-icons/ PS: It will be easier for us if you could post your code. So that actual issue can be pointed out. – Rishi Sep 25 '17 at 09:46

1 Answers1

0

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