2017-09-06 119 views
-2

如何在Swift 3中創建UIToolbar?我想要在左邊的一個動作,在右邊的動作和中間的標題像大多數應用程序一樣。它也看起來像沒有後退箭頭或堆棧的導航控制器。在Swift 3中創建UIToolbar

的代碼是這樣的:

let buttona = UIBarButtonItem(title: "Buttona", style: .plain, target: self, action: #selector(buttonaToolbar(sender:))); 
let buttonb = UIBarButtonItem(title: "Buttonb", style: .plain, target: self, action: #selector(buttonbToolbar(sender:))); 

let title = UILabel(); 

toolbar = UIToolbar(frame: CGRect(x: 0, y: 0, width: self.view.bounds.width, height: 44)); 
+0

我不需要堆回去 – cdub

+0

如果你不需要任何內置的方法的UINavigationController,會使自定義視圖模仿它足夠嗎? – solenoid

+0

@matt我確實按照你的意見 – cdub

回答

1

這裏是使中間有兩個按鈕的工具欄和標題中使用快捷3路:

func createToolbar(){ 
// ToolBar 
    let toolBar = UIToolbar() 
    toolBar.barStyle = .blackTranslucent 
    toolBar.isTranslucent = true 
    toolBar.backgroundColor = UIColor.blue 
    toolBar.tintColor = UIColor.white 
    toolBar.sizeToFit() 
    // Adding Button ToolBar 
    let doneButton = UIBarButtonItem(title: "Done", style: .plain, target: self, action: #selector(EnqiryViewController.doneClick)) 
    let spaceButton = UIBarButtonItem(barButtonSystemItem: .flexibleSpace, target: nil, action: nil) 
    let cancelButton = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(YourViewContreoller.cancelClick)) 
    toolBar.setItems([cancelButton, spaceButton, doneButton], animated: false) 
    toolBar.isUserInteractionEnabled = true 
} 

現在寫的函數的動作:

func doneClick() { 
    //do something here 
} 

func cancelClick() { 
    //do something here 
}