Randy Windin Randy Windin -4 years ago 123
iOS Question

button.isHidden to disappear again after being button view(background) is tapped on again

Still new to swift, but was having some fun with storyboard and with hiding and showing buttons. I created a storyboard with an image view that fills the whole view, and a button that lies on top of it called the overView. I also created a button called the searchButton that is on top of the overView. I so far am pretty stoked I got something this easy to work but need some more help. When the user clicks on the screen,(overView button), the searchButton appears. Great! But I want it (searchButton) to disappear once tapped on again. If someone could help me, that would be great. Thanks, here's my code

@IBOutlet weak var mainImage: UIImageView!
@IBOutlet weak var searchButton: UIButton!
override func viewDidLoad() {
super.viewDidLoad()
searchButton.isHidden = true
// Do any additional setup after loading the view, typically from a nib.
}

@IBOutlet weak var overView: UIButton!
@IBAction func overView(_ sender: Any) {
searchButton.isHidden = false
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}


Thanks

Answer Source

Try this:

@IBAction func overView(_ sender: Any) {
    searchButton.isHidden = !searchButton.isHidden
}

And if your searchButton is cover overView then try this:

@IBAction func onTapSearchButton(_ sender: Any) {
    searchButton.isHidden = true
}
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download