gpt4 book ai didi

ios - 带图像的按钮,点击按钮时图像消失 iOS 10

转载 作者:行者123 更新时间:2023-11-30 12:39:19 25 4
gpt4 key购买 nike

@IBAction func btnPrimaryAction(_ sender: Any) {
btnPrimary.setImage(UIImage(named : "checkbox_on.png") , for: UIControlState.normal)
btnSecondary.setImage(UIImage(named : "checkbox_off.png"), for: UIControlState.normal)
btnNewAdd.setImage(UIImage(named : "checkbox_off.png") , for: UIControlState.normal)
payType = 1
}

我使用此代码在单击按钮时更改按钮图像。但在 iOS 10 中单击按钮时按钮图像消失。

请帮我解决这个问题谢谢提前

最佳答案

我认为这是使用 UIButton 的有效方法状态。 UIButton有多个状态,如 UIControlState.normal,UIControlState.selected,UIControlState.highlighted ETC..您可以使用 UIButton 的 UIControlState 轻松解决您的问题。首先,您需要像这样将图像设置为按钮。在 viewDidLoad方法。

// if you have add the "checkbox_off.png and checkbox_on.png" in Images.xcassets then get the image you need to write as below
//UIImage(named : "checkbox_off") no need to add extention like ".png"

btnPrimary.setImage(UIImage(named : "checkbox_off.png") , for: UIControlState.normal)
btnSecondary.setImage(UIImage(named : "checkbox_off.png"), for: UIControlState.normal)
btnNewAdd.setImage(UIImage(named : "checkbox_off.png") , for: UIControlState.normal)

// Selected
btnPrimary.setImage(UIImage(named : "checkbox_on.png") , for: UIControlState.selected)
btnSecondary.setImage(UIImage(named : "checkbox_on.png"), for: UIControlState.selected)
btnNewAdd.setImage(UIImage(named : "checkbox_on.png") , for: UIControlState.selected)

现在在您的函数中只需更改按钮状态

@IBAction func btnPrimaryAction(_ sender: Any) {
btnPrimary.selected = true
btnSecondary.selected = false
btnNewAdd.selected = false
payType = 1
}

关于ios - 带图像的按钮,点击按钮时图像消失 iOS 10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42448165/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com