티스토리 뷰

 

viewDidLoad에서 delegate설정

 

    /// textview 설정

commentTextView.delegate = self
commentTextView.text =  "댓글 내용 입력"
commentTextView.textColor = UIColor.darkGray

    

 

extension 써주기

extension CreatePostingViewController: UITextViewDelegate {
  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 = "내용을 입력해주세요."
      textView.textColor = UIColor.lightGray
    }
  }
}

 

[출처]

stackoverflow.com/questions/27652227/how-can-i-add-placeholder-text-inside-of-a-uitextview-in-swift

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/11   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
글 보관함