gpt4 book ai didi

ios - 我想在点击它时更改 UIButton 图像

转载 作者:行者123 更新时间:2023-11-28 08:23:47 25 4
gpt4 key购买 nike

我在 CollectionViewController 的标题中有 2 个按钮。当我点击其中一个按钮时,我正在使用 UIControlState -> .normal .selected 更改此按钮的图像。

override func viewDidLoad() {
super.viewDidLoad()
collectionView.delegate = self
collectionView.dataSource = self

engSwitchButton.setImage(#imageLiteral(resourceName: "abc"), for: .normal)
geoSwitchButton.setImage(#imageLiteral(resourceName: "abg"), for: .normal)
engSwitchButton.setImage(#imageLiteral(resourceName: "abc2"),for: UIControlState.selected)
geoSwitchButton.setImage(#imageLiteral(resourceName: "abg2"), for: UIControlState.selected)


engSwitchButton.tag = Language.english.rawInt
geoSwitchButton.tag = Language.georgian.rawInt
}



@IBAction func languageSwitchTapped(_ sender: UIButton) {

sender.isSelected = !sender.isSelected



selectedLanguage = Language(rawInt: sender.tag)!
collectionView.reloadData()
}

我想要我首先点击的按钮,当我通过点击它来更改 2d 按钮的状态时返回到正常状态。

最佳答案

要在点击时更改按钮图像,您应该使用 UIControlState.highlighted

所以改变:

engSwitchButton.setImage(#imageLiteral(resourceName: "abc2"),for: UIControlState.selected)
geoSwitchButton.setImage(#imageLiteral(resourceName: "abg2"), for: UIControlState.selected)

对此:

engSwitchButton.setImage(#imageLiteral(resourceName: "abc2"),for: UIControlState.highlighted)
geoSwitchButton.setImage(#imageLiteral(resourceName: "abg2"), for: UIControlState.highlighted)

关于ios - 我想在点击它时更改 UIButton 图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40634375/

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