2017-05-23 38 views
0

自定義欄按鈕我得到的問題,當我使用自定義欄按鈕用圖像和標題,我用下面的代碼用圖片和標題

let button = UIButton(type: .system) 
    button.titleEdgeInsets.left = 5 
    button.setImage(buttonImg, for: .normal) 
    button.setTitle(title, for: .normal) 
    button.sizeToFit() 
    button.addTarget(self, action: #selector(self.popVC), for: .touchUpInside) 
    navigationItem.leftBarButtonItem = UIBarButtonItem(customView: button) 

而且這是問題所在片段。文字無法清楚地顯示

The text not shows clearly

回答

-1

試試這個:

let backButton = UIButton(type: .system) 
    backButton.frame = CGRect(x: 0, y: 0, width: 500, height: 30) 
    backButton.setImage(buttonImg, for: .normal) 
    backButton.setTitle(title, for: .normal) 
    backButton.addTarget(self, action: #selector(self.popVC(_:)), for: .touchUpInside) 
    backButton.sizeToFit() 
    let backBarButton = UIBarButtonItem(customView: backButton) 
    self.navigationItem.leftBarButtonItem = backBarButton 
+0

感謝您的答覆,但現在使用此代碼標題不會出現。 –

+0

我已經更新了我的答案..那個.. – PGDev

+0

我不想修復按鈕寬度謝謝 –