코딩

swift playholder 글씨 색상 바꾸는 방법 알아보자

kingarthur 2024. 7. 10. 01:06

오늘... 이것도 알아본다고 시간이 오래 걸렸다.

역시 작은 기능도 쉽지 않다고 생각했다. 

 

처음 겪은 오류?? 플레이홀더 쓰면서 글씨가 안보이면서 문제를 겪었다

평소 쓰는 playceholder는  글자 색상이... 약해서 배경이 어두우면 안보이게 된다.

아주 치명적이라 방법을 찾아봤다.

 

첫번째 해결 방법을

    var memoField: UITextField = {
        let label = UITextField()
        label.textColor = .white
        let placeholderAttributes: [NSAttributedString.Key: Any] = [
            .foregroundColor: UIColor.white,
            .font: UIFont.systemFont(ofSize: 20)
        ]
        label.attributedPlaceholder = NSAttributedString(string: "메모 내용을 입력해주세요.", attributes: placeholderAttributes)
        label.textAlignment = .center
        label.font = .boldSystemFont(ofSize: 20)
        label.layer.cornerRadius = 20
        label.layer.borderWidth = 3
        label.layer.borderColor = UIColor.white.cgColor
        label.translatesAutoresizingMaskIntoConstraints = false
        return label
    }()

 

플레이스 홀더 대신 어트리뷰트를 사용하면서 해결을 했다. 

 

작은 기능이지만 해결해서 기분은 좋았다.

아직 오류가 많아 빨리 해결해보자 아자!

반응형