0

I have two UIButton on the right side of navigation bar of UIViewController, UIbuttons have images. The app was working fine till it was running in Xcode 8, but when I updated Xcode 9 it is not rendering, it is taking whole navigation bar. In Xcode 8 it was enter image description here

but after updating to Xcode 9 it looks like this

enter image description here

My code to setting navbar is ...

  func setUpNavBar(){
    self.navigationController?.navigationBar.isTranslucent = false
    self.navigationItem.setHidesBackButton(true, animated: true)


    let notificationBtn = UIButton(type: .custom)
    notificationBtn.setImage(UIImage(named: "notificationIcon"), for: .normal)
    notificationBtn.frame = CGRect(x: 0, y: 0, width: 35, height: 35)
    notificationBtn.addTarget(self, action: #selector(HomeViewController.notificationClicked), for: .touchUpInside)
    let item1 = UIBarButtonItem(customView: notificationBtn)

    let profileBtn = UIButton(type: .custom)
    profileBtn.setImage(UIImage(named: "user_profile"), for: .normal)
    profileBtn.frame = CGRect(x: 0, y: 0, width: 35, height: 35)
     profileBtn.addTarget(self, action: #selector(HomeViewController.ProfileClicked), for: .touchUpInside)
    let item2 = UIBarButtonItem(customView: profileBtn)
    self.navigationItem.setRightBarButtonItems([item1,item2], animated: true)

}

I am very confused why it is happening.

Prathamesh
  • 140
  • 1
  • 2
  • 15

1 Answers1

2

In iOS 11 you need to add/set constraints of height and with of UIButton

For notificationBtn

let widthConstraint = notificationBtn.widthAnchor.constraint(equalToConstant: 35)
let heightConstraint = notificationBtn.heightAnchor.constraint(equalToConstant: 35)
heightConstraint.isActive = true
widthConstraint.isActive = true

Apply same for profileBtn too.

iPatel
  • 46,010
  • 16
  • 115
  • 137