Last active
May 14, 2019 10:04
-
-
Save jamesgathu/b340b038348eb056a182446ce8e31b55 to your computer and use it in GitHub Desktop.
iOS add placeholder to UITextView
This file contains 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
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