Skip to content

Instantly share code, notes, and snippets.

@fethica
Created February 25, 2021 03:26
Show Gist options
  • Save fethica/d9a8bba8dfeca4d6ae42de5e4ca5a317 to your computer and use it in GitHub Desktop.
Save fethica/d9a8bba8dfeca4d6ae42de5e4ca5a317 to your computer and use it in GitHub Desktop.
// source: https://stackoverflow.com/questions/27652227/add-placeholder-text-inside-uitextview-in-swift
textView.text = "Placeholder"
textView.textColor = UIColor.lightGray
func textViewDidBeginEditing(_ textView: UITextView) {
guard textView.textColor == UIColor.lightGray else { return }
textView.text = nil
textView.textColor = UIColor.black
}
func textViewDidEndEditing(_ textView: UITextView) {
guard textView.text.isEmpty else { return }
textView.text = "Placeholder"
textView.textColor = UIColor.lightGray
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment