Home I want to change UIButton Image when tapped on it
Reply: 0

I want to change UIButton Image when tapped on it

user1113 Published in June 20, 2018, 7:19 am

I have 2 buttons in header on CollectionViewController. When i tap on one of them i'm changing an image of this buttons using UIControlState -> .normal .selected.

override func 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)!

I want the button which i tapped first, get back to .normal state when i'm changing state of 2d button with tapping on it.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.383735 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO