Skip to content

Instantly share code, notes, and snippets.

@chris-hatton
Last active December 7, 2016 04:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chris-hatton/bad4493cec094f918572bc656693a7ed to your computer and use it in GitHub Desktop.
Save chris-hatton/bad4493cec094f918572bc656693a7ed to your computer and use it in GitHub Desktop.
import UIKit
final class RubberDuckyController : UIViewController {
@IBOutlet weak var leftButton : UIButton!
@IBOutlet weak var rightButton : UIButton!
@IBOutlet weak var textLeftButtonUnderline : UIView!
@IBOutlet weak var shapeRightButtonUnderline : UIView!
enum Selection {
case left
case right
}
private var selection : Selection = .left {
didSet {
guard selection != oldValue else { return }
refreshSelection()
}
}
public override func viewDidLoad() {
super.viewDidLoad()
refreshSelection()
}
private func refreshSelection() {
textLeftButtonUnderline .isHidden = (selection != .left ) // Hide the left underline if left is not selected
shapeRightButtonUnderline.isHidden = (selection != .right) // Hide the right underline if right is not selected
}
// Hook both button's touchUpInside events to this IBAction
@IBAction func onButtonTapped(_ sender: UIButton) {
switch sender {
case leftButton : selection = .left
case rightButton : selection = .right
default: assertionFailure() // This can only happen if an unexpected sender
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment