[iOS] UITextField PlaceHolder
2024. 3. 24. 21:46
1. TextField 선언하기
private lazy var textView: UITextView = {
let textView = UITextView()
textView.delegate = self
textView.textColor = .secondaryLabel
textView.font = .systemFont(ofSize: 16.0, weight: .medium)
textView.text = "" // PlaceHolder Text 입력
return textView
}()
2. UITextViewDelegate - textViewDidBeginEditing 사용
extension ViewController: UITextViewDelegate{
func textViewDidBeginEditing(_ textView: UITextView) {
// TextColor가 secondaryLabel이 아닐 때 새로 입력
guard textView.textColor == .secondaryLabel else {return}
textView.text = nil
textView.textColor = .label
}
}
728x90
'iOS > UIKit' 카테고리의 다른 글
UIModalPresentationStyle (0) | 2024.11.17 |
---|---|
[iOS] UICollectionViewCompositionalLayout (0) | 2024.03.09 |
[iOS] UIScrollView (1) | 2024.03.09 |
[iOS] @IBInspectable (0) | 2024.01.06 |
[iOS] 키보드 처리 (0) | 2023.12.30 |