Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Show / Hide Image in Swift

how to show or hide a image in Swift by taping on a Button? For example:

i have ImageA and ImageB and one Button which i want to use to move ImageA to ImageB and back to ImageA and so on..

It works perfect to move from ImageA to ImageB, but how can i move back to ImageA?

My code is:

import UIKit

class ViewController: UIViewController {

@IBOutlet weak var Bild1: UIImageView!
@IBOutlet weak var Bild2: UIImageView!

@IBAction func pressedButton(sender: AnyObject) {

    Bild1.hidden = true
    Bild2.hidden = false
}


override func viewDidLoad() {
    super.viewDidLoad()

    Bild1.hidden = false
    Bild2.hidden = true

    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}


}
like image 512
Xeven Elewen Avatar asked Dec 18 '22 16:12

Xeven Elewen


1 Answers

override func viewDidLoad()
{
    super.viewDidLoad()

    Bild1.isHidden = false
    Bild2.isHidden = true
    // Do any additional setup after loading the view, typically from a nib.
}

@IBAction func pressedButton(sender: AnyObject) 
{
    Bild1.isHidden = !Bild1.isHidden
    Bild2.isHidden = !Bild2.isHidden
}
like image 181
Jayesh Miruliya Avatar answered Jan 05 '23 05:01

Jayesh Miruliya