let ideaTextView = UITextView()
let placeHolderLabel = UILabel()
placeHolderLabel.text = "写下你的问题或建议,我们将及时跟进解决(建议上传截图帮助我们解决问题,感谢!)"
placeHolderLabel.numberOfLines = 0
placeHolderLabel.font = UIFont.systemFont(ofSize: 15)
placeHolderLabel.textColor = UIColor.lightGray
placeHolderLabel.sizeToFit()
ideaTextView.addSubview(placeHolderLabel)
ideaTextView .setValue(placeHolderLabel, forKeyPath: "_placeholderLabel")
ideaTextView.font = placeHolderLabel.font
或者
class PlaceholderTextView: UITextView {
lazy var placeholderTextView: UITextView = {
let placeholderTextView = UITextView()
placeholderTextView.backgroundColor = .clear
placeholderTextView.textColor = UIColor.itForegroundPlacehol