更新到 Xcode 9 后导航栏按钮中的图像未呈现

Image in navigation bar button not rendering after updating to Xcode 9

我在UIViewController的导航栏右侧有两个UIButton,UIbuttons有图片。该应用程序工作正常,直到它在 Xcode 8 中变为 运行,但是当我更新 Xcode 9 时它没有呈现,它占用了整个导航栏。 在 Xcode 8 中是

但更新到 Xcode 9 后看起来像这样

我设置导航栏的代码是...

  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)

}

我很困惑为什么会这样。

iOS 11中你需要add/set限制高度和UIButton

对于notificationBtn

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

同样适用于 profileBtn