LoginSignup
31
36

More than 5 years have passed since last update.

Navigation Controller の "戻る/back" ボタンをカスタマイズする

Posted at

NavigationItem の BarButtonItem をカスタマイズする

Navigation Controller は画面遷移をコードを書かずにサポートしてくれるのでよく使います。

戻る際のボタンも NavgitationItem の title プロパティの値を自動で設定してくれたり便利ではありますが、
title プロパティを設定しない場合、下記のように "Back" と表示されてしまいます。

Screen Shot 2014-07-08 at 23.17.40.png

ここのテキストの内容を変更したい場合、新たに UIBarButtonItem を生成する必要があります。

    UIBarButtonItem *barButton = [[UIBarButtonItem alloc] init];
    barButton.title = @"戻る";
    self.navigationItem.backBarButtonItem = barButton;

ポイントは 遷移元("Back" ボタンが表示される前)の ViewController に書くことです。戻るボタンを設定しているので言われてみるとそうだなーと思いますが。

Screen Shot 2014-07-08 at 23.47.26.png

これで自由にテキストを設定できるようになりました。

31
36
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
31
36