facebook twitter hatena line email

「Ios/swift/ナビゲーションバー/右上にボタンを追加」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
行1: 行1:
==サンプル==
+
==アイコンボタンの場合==
 
     override func viewDidLoad() {
 
     override func viewDidLoad() {
 
         super.viewDidLoad()
 
         super.viewDidLoad()
 
         let rightBookmarkBarButtonItem: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Bookmarks, target: self, action: #selector(self.bookmarkButtonTapped))
 
         let rightBookmarkBarButtonItem: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Bookmarks, target: self, action: #selector(self.bookmarkButtonTapped))
 +
        self.navigationItem.setRightBarButtonItems([rightBookmarkBarButtonItem], animated: true)
 +
    }
 +
    func bookmarkButtonTapped() {
 +
    }
 +
 +
==テキストボタンの場合==
 +
    override func viewDidLoad() {
 +
        super.viewDidLoad()
 +
        let rightBookmarkBarButtonItem = UIBarButtonItem(title: "☆", style: .Plain, target: nil, action: nil)
 +
        navigationItem.backBarButtonItem = backButtonItem
 
         self.navigationItem.setRightBarButtonItems([rightBookmarkBarButtonItem], animated: true)
 
         self.navigationItem.setRightBarButtonItems([rightBookmarkBarButtonItem], animated: true)
 
     }
 
     }
 
     func bookmarkButtonTapped() {
 
     func bookmarkButtonTapped() {
 
     }
 
     }

2016年7月29日 (金) 21:46時点における版

アイコンボタンの場合

   override func viewDidLoad() {
       super.viewDidLoad()
       let rightBookmarkBarButtonItem: UIBarButtonItem = UIBarButtonItem(barButtonSystemItem: UIBarButtonSystemItem.Bookmarks, target: self, action: #selector(self.bookmarkButtonTapped))
       self.navigationItem.setRightBarButtonItems([rightBookmarkBarButtonItem], animated: true)
   }
   func bookmarkButtonTapped() {
   }

テキストボタンの場合

   override func viewDidLoad() {
       super.viewDidLoad()
       let rightBookmarkBarButtonItem = UIBarButtonItem(title: "☆", style: .Plain, target: nil, action: nil)
       navigationItem.backBarButtonItem = backButtonItem
       self.navigationItem.setRightBarButtonItems([rightBookmarkBarButtonItem], animated: true)
   }
   func bookmarkButtonTapped() {
   }