質問

私は、インフォボタンuinavigationbar上(「i」のそれの周りに円と手紙を)持っているアプリケーションの多くを見てきました。どのように私はこのタイプのボタンを追加できますか?

役に立ちましたか?

解決

前の答えは近くにあった、非常にコンパイルされませんでした。ここではあなたが本当に欲しいものです。

// Info button
UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; 
[infoButton addTarget:self action:@selector(showInfoView:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:infoButton];

他のヒント

上記の回答でメモリリークがあります。あなたはそれを避けるために「自動解放」を使用する必要があります。私は答えを編集しようとしたが、私は今のところ成功しませんでした。

// Info button
UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; 
[infoButton addTarget:self action:@selector(showInfoView:) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:infoButton] autorelease];

これはそれを行うための正しい方法です。

あなたはUINavigationControllerは、現在表示しているビューコントローラのnavigationItemに「情報ライト」タイプのボタンを追加することができるはずです。このような何かがあなたのビューコントローラのコードに行くことができます:

- (void) viewDidLoad {
  UIButton * info = [UIButton buttonWithType:UIButtonTypeInfoLight];
  // set your button's target and selector for whatever action here.
  self.navigationItem.rightBarButtonItem.customView = info;
}

また、あなたの情報ボタンのためのあなたの現在のバーボタンアイテムのターゲットとセレクタを使用することができます。

UIButton *infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight];
[infoButton addTarget:self.barButtonItem.target action:self.barButtonItem.action forControlEvents:UIControlEventTouchUpInside];
self.barButtonItem.customView = infoButton;

この方法では、あなたのバーボタンアイテムに結合された任意のアクションやseguesは、あなたの情報ボタンに転送されます。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top