My application uses an UITextView. Now I want the UITextView to have a placeholder similar to the one you can set for an UITextField.<
Simple Swift 3 solution
Add UITextViewDelegate to your class
Set yourTextView.delegate = self
Create placeholderLabel and position it inside yourTextView
Now just animate placeholderLabel.alpha on textViewDidChange:
func textViewDidChange(_ textView: UITextView) {
let newAlpha: CGFloat = textView.text.isEmpty ? 1 : 0
if placeholderLabel.alpha != newAlpha {
UIView.animate(withDuration: 0.3) {
self.placeholderLabel.alpha = newAlpha
}
}
}
you might have to play with placeholderLabel position to set it up right, but that shouldn't be too hard