2017-05-05 52 views
0

導航標題我想這樣做:圖標旁邊用斯威夫特3

enter image description here

關於右側的按鈕,我這樣做:

let buttonRight = UIBarButtonItem(image: UIImage(named: "back"), style: .done, target: self, action: nil) 
let textRight = UIBarButtonItem(title: "Mixte", style: .done, target: self, action: nil) 

self.navigationItem.rightBarButtonItems = [textRight, buttonRight] 

但我不能改變圖像的大小,點擊文字與圖像上的點擊不同(點擊是分開的)。

我想只有一個點擊兩個。

現在,對於中間的標題,我真的不知道該怎麼做。

回答

0

要使這兩個按鈕執行相同的方法,您需要添加一個選擇器。

let buttonRight = UIBarButtonItem(image: UIImage(named: "back"), style: .done, target: self, action: #selector(YourViewController.doSomething(_:)) 
let textRight = UIBarButtonItem(title: "Mixte", style: .done, target: self, action: #selector(YourViewController.doSomething(_:)) 

class YourViewController: UIViewController { 
    func doSomething(_ sender: AnyObject){ 
     // 
    } 
} 
+0

不,它不工作...當我點擊texte例如,顏色只改變texte,並且相同的圖標:/ – KevinB