0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

NavigationBar (複数のItem追加) (左右) 復習

Posted at

今回の内容

  • NavigationBarの左右にItemを追加

  • NavigationBarにItemを複数個、追加

コードと簡単解説

左側にUIBarButtonItemを追加

  • ボタンにImageを付けずに、任意のtitleで作成

  • action:は任意で#selector(@objc method)などで設定します。(今回は.none)

navigationItem.leftBarButtonItem = UIBarButtonItem(title: "左ボタン", style: .done, target: self, action: .none)

右側にUIBarButtonItemを追加

  • ボタンに.actionのImageを設定したボタンを作成

  • action:は任意で#selector(@objc method)などで設定します。(今回は.none)

navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .action, target: self, action: .none)

複数のUIBarButtonItemを追加

  • .rightBarButtonItemsなら右側に追加

  • .leftBarButtonItemsなら左側に追加

  • 追加するUIBarButtonItemの内容は、配列に入れる

navigationItem.rightBarButtonItems = [UIBarButtonItem(barButtonSystemItem: .action, target: self, action: .none),
                                      UIBarButtonItem(title: "右ボタン", style: .done, target: self, action: .none)]

終わり

昨日、調べた内容の復習です。
ご指摘、ご質問などありましたら、コメントまでお願い致します。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?