LoginSignup
5
5

More than 5 years have passed since last update.

UIBarButtonItemにhighlight用の画像を設定したい場合

Last updated at Posted at 2013-02-04

ナビゲーションバーに設定する画像について
ボタンを押した時に画像を割り当てたいと思って探したら、なかなか見つからなかったので
自分の実現方法を纏めます。


    UIButton* rightBarCustomButton =[[UIButton alloc]initWithFrame:CGRectMake(0, 0, 70, 30)];
    [rightBarCustomButton setBackgroundImage:[UIImage imageNamed:@"button_blue.png"] forState:UIControlStateNormal];
    [rightBarCustomButton setBackgroundImage:[UIImage imageNamed:@"button_blue_highlight.png"] forState:UIControlStateHighlighted];

    //buttonのラベル設定
    [rightBarCustomButton setTitle:@"share" forState:UIControlStateNormal];
    rightBarCustomButton.titleLabel.font =[UIFont boldSystemFontOfSize:14];
    rightBarCustomButton.titleLabel.shadowOffset    = CGSizeMake (0.0, 1.0);
    rightBarCustomButton.titleLabel.shadowColor =[UIColor blackColor];

    [rightBarCustomButton addTarget:self action:@selector(share:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBarCustomButton];
    [self.navigationItem setRightBarButtonItem:rightBarButtonItem];

5
5
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
5
5