새소식

iOS/UIKit

[iOS] UITextField PlaceHolder

  • -

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' 카테고리의 다른 글

[iOS] UICollectionViewCompositionalLayout  (0) 2024.03.09
[iOS] UIScrollView  (1) 2024.03.09
[iOS] @IBInspectable  (0) 2024.01.06
[iOS] 키보드 처리  (0) 2023.12.30
[iOS] 기종별로(iPhone, iPad) StoryBoard 구분하기  (1) 2023.12.30
Contents

포스팅 주소를 복사했습니다

이 글이 도움이 되었다면 공감 부탁드립니다.