Skip to content

Instantly share code, notes, and snippets.

@jamesgathu
Last active May 14, 2019 10:04
Show Gist options
  • Save jamesgathu/b340b038348eb056a182446ce8e31b55 to your computer and use it in GitHub Desktop.
Save jamesgathu/b340b038348eb056a182446ce8e31b55 to your computer and use it in GitHub Desktop.
iOS add placeholder to UITextView
class Viewcontroller : UIViewController, UITextViewDelegate{
override func viewDidLoad(){
super.viewDidLoad()
textView.text = "Placeholder"
textView.textColor = UIColor.lightGray
}
func textViewDidBeginEditing(_ textView: UITextView) {
if textView.textColor == UIColor.lightGray {
textView.text = nil
textView.textColor = UIColor.black
}
}
func textViewDidEndEditing(_ textView: UITextView) {
if textView.text.isEmpty {
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