Last active
December 7, 2016 04:19
-
-
Save chris-hatton/bad4493cec094f918572bc656693a7ed to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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