2017-10-12 54 views
0

我在UIViewController的導航欄的右側有兩個UIButton,UIbuttons有圖像。該應用程序工作正常,直到它在Xcode 8中運行,但是當我更新Xcode 9時,它不是呈現,而是整個導航欄。 在Xcode中8是 enter image description here更新到Xcode 9後導航欄按鈕中沒有渲染圖像

但更新到Xcode中9後,它看起來像這樣

enter image description here

我的代碼來設置導航欄是...

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) 

} 

我很困惑它爲什麼會發生。

回答

2

iOS 11你需要添加/身高的一系列約束和與UIButton

對於notificationBtn

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

profileBtn應用一樣了。

+0

我認爲你應該標記爲重複大聲笑 –

+1

它的作品感謝人 – Prathamesh