Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
Created September 8, 2016 14:21
Show Gist options
  • Save KentarouKanno/51a05204626ae8913b52fbf4fd51e9ed to your computer and use it in GitHub Desktop.
Save KentarouKanno/51a05204626ae8913b52fbf4fd51e9ed to your computer and use it in GitHub Desktop.
UINavigationItem

UINavigationItem

★ 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!")
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment