gavanwanggw

导航

navigationItem.rightBarButtonItem 设置背景图片,颜色更改解决的方法

self.navigationItem.rightBarButtonItem=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"MoreImage"] style:UIBarButtonItemStylePlain target:self action:@selector(moreItemPress)];

     用这样的方法。设置的背景图片,颜色变掉了。不是原来设置的图片颜色。

     能够用第二种方式,能够解决变色的问题。

UIButton*rightButton = [[UIButton alloc]initWithFrame:CGRectMake(0,0,30,30)];

[rightButton setImage:[UIImage imageNamed:@"MoreImage"] forState:UIControlStateNormal];

[rightButton addTarget:self action:@selector(moreItemPress) forControlEvents:UIControlEventTouchUpInside];

UIBarButtonItem*rightItem = [[UIBarButtonItem alloc]initWithCustomView:rightButton];

self.navigationItem.rightBarButtonItem= rightItem;




posted on 2017-08-17 09:15  gavanwanggw  阅读(201)  评论(0编辑  收藏  举报