2011-08-10 9 views
0

このコードを変更して、ナビゲーションバーの右端に単語の代わりに情報ボタンを表示するにはどうすればよいですか?ナビゲーションバーのインフォメーションライトボタン

- (void)viewDidLoad { 
    [self setTitle:@"About"]; 
    [super viewDidLoad]; 
    UIBarButtonItem *addButton = [[[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"info", @"") 
                  style:UIBarButtonItemStyleBordered 
                  target:self 
                  action:@selector(addAction:)] autorelease]; 
    self.navigationItem.rightBarButtonItem = addButton; 
} 

答えて

2

この質問はよく質問されています。

 UIImage *buttonImage = [UIImage imageNamed:@"UIButtonInformationIcon.jpg"]; 
     //create the button and assign the image 
     UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom]; 
     [button setImage:buttonImage forState:UIControlStateNormal]; 
     //set the frame of the button to the size of the image 
     button.frame = CGRectMake(0, 0, buttonImage.size.width, buttonImage.size.height); 

     [button addTarget:self action:@selector(anyActionYouWant) forControlEvents:UIControlEventTouchUpInside]; 
     //create a UIBarButtonItem with the button as a custom view 

     self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc] initWithCustomView:button]autorelease]; 

ここではいくつかの解決策があります。

+0

いい仕事...驚いた誰もupvoted? – jsetting32

0

または、タイトルバーにボタンを追加するときに、ドロップダウンリストから選択することができます。ボタンの種類は任意です。 「情報ライト」タイプを選択する必要があります。

関連する問題