★ NavigationTitleにボタンを設定する
import UIKit
class ViewController: UIViewController {
var titleButton = UIButton(type: .Custom)
override func viewDidLoad() {
super.viewDidLoad()
titleButton.setTitle("タイトル名", forState: .Normal)
titleButton.backgroundColor = UIColor.redColor()
titleButton.frame = CGRect(x: 0, y: 0, width: 100, height: 40)
titleButton.addTarget(self, action: #selector(ViewController.pushTittle(_:)), forControlEvents: .TouchUpInside)
self.navigationItem.titleView = titleButton
}
func pushTittle(sender: UIButton) {
print("Push Button!")
}
}