I have some buttons in my class that show or hide two views (by setting their alpha property to either 0 or 1) when the user taps on them. I have written a function that uses the tag
property of the sender
of the button (which is passed to the function by default) to identify which view to show or hide:
@IBAction func showOrHideView(sender: AnyObject) {
UIView.animateWithDuration(0.5, animations: {
switch sender.tag {
case 1:
self.viewSketchpad.alpha = self.viewSketchpad.alpha == 1 ? 0 : 1
case 2:
self.viewTips.alpha = self.viewTips.alpha == 1 ? 0 : 1
default:
break
}
})
}
How can I make this code cleaner?