ナビゲーションバーにカスタムの「設定」ボタンを作成する必要があります。ただ、残念ながら絵コンテエディタでうまく取り込めませんでした。ボタンの四角形ではなく、自分の写真だけを表示する必要があります。
ボタンの種類を正しく作る方法はありますか?
ありがとう。
ナビゲーションバーにカスタムの「設定」ボタンを作成する必要があります。ただ、残念ながら絵コンテエディタでうまく取り込めませんでした。ボタンの四角形ではなく、自分の写真だけを表示する必要があります。
ボタンの種類を正しく作る方法はありますか?
ありがとう。
このコードを ViewController-viewDidLoad
メソッドに追加できます。
左バーボタンの場合:
UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *buttonImage = [UIImage imageNamed:@"NavBarMapBtn.png"];
[leftButton setImage:buttonImage forState:UIControlStateNormal];
leftButton.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);
[leftButton addTarget:self action:@selector(changeView) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftButton];
または右バーボタンの場合:
UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeCustom];
UIImage *buttonImage = [UIImage imageNamed:@"NavBarMapBtn.png"];
[rightButton setImage:buttonImage forState:UIControlStateNormal];
rightButton.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height);
[rightButton addTarget:self action:@selector(changeView) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightButton];
BarButtonItem を xib またはストーリーボードのビューに追加する必要はありません。
これは次のようになります。