[英]Swift: How to Change UIButton Image on clicking submit button
I have four UIButtons which act as checkboxes, on tapping the button, the image changes. 我有四个UIButton,它们充当复选框,在点击按钮时,图像会更改。 I have a submit button, where I perform a certain operation. 我有一个提交按钮,可以在其中执行某些操作。 My question is How do I change the image of the checkbox UIButton to normal and remove the data in textfield on clicking the submit button. 我的问题是如何单击“提交”按钮将复选框UIButton的图像更改为正常图像,并删除文本字段中的数据。
@IBAction func submitActn(sender : UIButton!){
checkBoxBtn.imageView?.image = UIImage(named: "image") //Similar for every checkBtn
textField1.text = ""
}
Or a much elegant way:- 或一种更优雅的方式:-
Go to your Storyboard -> Select your buttons one at a time -> open Their Attributes Inspector -> 转到情节提要 ->一次选择一个按钮->打开“他们的属性”检查器 ->
For State Config -Default, select a image in image
box just below that you want to show as default(uncheck image ) 对于State Config -Default,在image
框中选择要显示为默认图像的图像(取消选中image)
For State Config -Selcted, select a image in image
box just below that you want to show as when the button is selected(checked image) 对于State Config -Selcted,在image
框中选择要在选择按钮时显示的图像(选中的图像)
@IBAction func submitActn(sender : UIButton!){
checkBtn1.selected = false
checkBtn2.selected = false
checkBtn3.selected = false
checkBtn4.selected = fasle
textField1.text = ""
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.