Skip to content

Instantly share code, notes, and snippets.

@darhonbek
Created January 15, 2018 14:17
Show Gist options
  • Save darhonbek/581db5aaa3f650398311081f41e7f8a1 to your computer and use it in GitHub Desktop.
Save darhonbek/581db5aaa3f650398311081f41e7f8a1 to your computer and use it in GitHub Desktop.
DevNotes for iOS beginners: Changing button's label
// Wrong
if bgAudioPlayer.isPlaying {
bgAudioPlayer.stop()
pausePlayButton.titleLabel?.text = "Play"
} else {
bgAudioPlayer.play()
pausePlayButton.titleLabel?.text = "Pause"
}
// Right
if bgAudioPlayer.isPlaying {
bgAudioPlayer.stop()
pausePlayButton.setTitle("Play", for: .normal)
} else {
bgAudioPlayer.play()
pausePlayButton.setTitle("Pause", for: .normal)
}
// #ios #devnotes #swift
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment