Skip to content

Instantly share code, notes, and snippets.

@aheze
Last active May 31, 2020 01:50
Show Gist options
  • Select an option

  • Save aheze/9708303f4403de246abb77cf4fcda7ed to your computer and use it in GitHub Desktop.

Select an option

Save aheze/9708303f4403de246abb77cf4fcda7ed to your computer and use it in GitHub Desktop.
let trumpImage = UIImage(named: "trump")
let borisImage = UIImage(named: "boris")
var personIsBoris = true
@IBOutlet weak var personImageView: UIImageView!
@IBOutlet weak var temperatureLabel: UILabel!
/// off = Celsius, on = Fahrenheit
var temperatureSwitchIsOn = true
@IBOutlet weak var temperatureSwitch: UISwitch!
@IBAction func temperatureSwitchToggled(_ sender: Any) {
temperatureSwitchIsOn = temperatureSwitch.isOn
personIsBoris = temperatureSwitch.isOn
if temperatureSwitchIsOn {
temperatureLabel.text = "32 °F"
} else {
temperatureLabel.text = "0 °C"
}
if personIsBoris {
personImageView.image = borisImage
} else {
personImageView.image = trumpImage
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment