[英]Error while Changing the image of the button from an image to another when clicked on the button
[英]Changing button image when another button is clicked
我在xcode中遇到问题,在我的一个视图控制器中,我有两个按钮,当单击其中一个按钮( appleBtn
)时,第二个按钮的( topMenu1Btn
)图像应更改
我为两个按钮都创建了一个插座,单击时为applebtn设置了一个动作
- (IBAction)HandleBtnClick:(id)sender {
self.topMenu1Btn.imageView = [UIImage imageNamed:@"Apple.jpg"]
}
问题是imageview是只读的,无论如何有做吗?
您可以尝试设置按钮的图像。
[self.topMenu1Bt setImage:[UIImage imageNamed:@"Apple.jpg"] forState:UIControlStateNormal]
如果要背景图像,请使用setBackgroundImage:
[self.topMenu1Btn setBackgroundImage:[UIImage imageNamed:@"Apple.jpg"] forState:UIControlStateNormal];
要么
[self.topMenu1Bt setImage:[UIImage imageNamed:@"Apple.jpg"] forState:UIControlStateNormal]
如果您使用第二种方法,请确保图像的边框与按钮匹配
确保按钮类型为自定义
- (IBAction)HandleBtnClick:(id)sender
{
[self.topMenu1Btn setBackgroundImage:[UIImage imageNamed:@"Apple.jpg"] forState:UIControlStateNormal];
}
您不能修改imageview,但是可以修改其中的图像;)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.