单击按钮时是否可以更改工具栏项目(2)背景图像或颜色
提前致谢
答案 0 :(得分:0)
你可以随时使用像这样的uibutton视图:
UIButton* button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)]; //or the size you need
//现在你可以设置一个图像
[button setBackgroundImage:image forState:UIControlStateNormal];
//或者您可以更改背景或其他任何内容
[button setBackgroundColor:[UIColor redColor]];
[botonFav setShowsTouchWhenHighlighted:YES]; //optional
[botonFav addTarget:self action:@selector(buttonAction) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithCustomView:button];
self.yourButton = btn;
//你应该像这样实现按钮动作:
-(void)buttonAction{
//your code here
}
我希望这就是你在哪里寻找
答案 1 :(得分:0)
您需要通过ctrl +从界面生成器拖动到头文件来为item2按钮创建属性。
@property (weak, nonatomic) UIButton *item2Button;
从你的button1,通过按住Ctrl +从按钮拖动到头文件创建一个IBAction,将其设置为动作
-(IBAction)buttonOnePressed:(id)sender;
在您的实现文件中,在此IBAction方法中,您可以根据需要更改item2Button的属性。
假设你已经为item2Button准备了一个按钮背景UIImage,就像 buttonImage 那样,那么在IBAction方法中输入这个
[self.item2Button setBackgroundImage:buttonImage forState:UIControlStateNormal];
我希望这很清楚,
干杯,吉姆。