在ios后台更改工具栏项
当我点击按钮(1)时,是否可以更改Toobar项目(2)背景图像或颜色在ios后台更改工具栏项,ios,toolbar,Ios,Toolbar,当我点击按钮(1)时,是否可以更改Toobar项目(2)背景图像或颜色 提前感谢您始终可以使用以下uibutton视图: UIButton* button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)]; //or the size you need -(void)buttonAction{ //your code here } //现在,您可以设置图像 [button setBackgroundImage:i
提前感谢您始终可以使用以下uibutton视图:
UIButton* button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)]; //or the size you need
-(void)buttonAction{
//your code here
}
//现在,您可以设置图像
[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;
//您应该执行如下按钮操作:
UIButton* button = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 30, 30)]; //or the size you need
-(void)buttonAction{
//your code here
}
我希望这就是您要查找的内容您需要通过按住ctrl键并将其从interface Builder拖动到头文件来创建item2按钮的属性
@property (weak, nonatomic) UIButton *item2Button;
在button1中,通过按住ctrl键并将其从按钮拖动到头文件来创建iAction,将其设置为操作
-(IBAction)buttonOnePressed:(id)sender;
在您的实现文件中,在此iAction方法中,您将能够根据需要更改item2Button的属性
假设您已经为item2Button准备好了一个按钮背景UIImage,名为buttonImage,那么在iAction方法中输入
[self.item2Button setBackgroundImage:buttonImage forState:UIControlStateNormal];
我希望这是清楚的,
干杯,吉姆。谢谢您的回复,但我想要的是,当我单击按钮“button”(1)时,我可以更改UIToolbar按钮的背景,该按钮在“item”(2)上方的图像中命名。谢谢