ios - Add placeholder text inside UITextView in Swift? - Stack Overflow

PHOTO EMBED

Tue Feb 07 2023 11:45:05 GMT+0000 (Coordinated Universal Time)

Saved by @Raihan #swift

import UIKit
class PlaceHolderTextView:UITextView, UITextViewDelegate{
var placeholderText = "placeholderText"

override func willMove(toSuperview newSuperview: UIView?) {
    textColor = .lightText
    delegate = self
}

func textViewDidBeginEditing(_ textView: UITextView) {
    if textView.text == placeholderText{
        placeholderText = textView.text
        textView.text = ""
        textView.textColor = .darkText
    }
}

func textViewDidEndEditing(_ textView: UITextView) {
    if textView.text == ""{
        textView.text = placeholderText
        textColor = .lightText
    }
}    
}
content_copyCOPY

https://stackoverflow.com/questions/27652227/add-placeholder-text-inside-uitextview-in-swift