在Swift中显示/隐藏图像 [英] Show / Hide Image in Swift
本文介绍了在Swift中显示/隐藏图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何通过点击按钮在Swift中显示或隐藏图像? 例如:
how to show or hide a image in Swift by taping on a Button? For example:
我有ImageA和ImageB,还有一个按钮,我想用它来将ImageA移至ImageB并移回ImageA,依此类推.
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..
从ImageA移至ImageB效果很好,但是我如何才能移回ImageA?
It works perfect to move from ImageA to ImageB, but how can i move back to ImageA?
我的代码是:
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.
}
}
推荐答案
@IBAction func pressedButton(sender: AnyObject)
{
if Bild2.tag == 0
{
Bild1.hidden = true
Bild2.hidden = false
Bild2.tag=1
}
else
{
Bild1.hidden = false
Bild2.hidden = true
Bild2.tag=0
}
}
override func viewDidLoad()
{
super.viewDidLoad()
Bild1.hidden = false
Bild2.hidden = true
Bild2.tag=0
// Do any additional setup after loading the view, typically from a nib.
}
这篇关于在Swift中显示/隐藏图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文