티스토리 뷰

이슈

textField 를 하나 만들어서 PlaceHolder 를 적용했고,

입력이 이루어지는 font 와 placeHolder 의 폰트를 다르게 하고 싶었으나 placeHolder.font 가 적용되지 않았다.

 

문제의 코드

let textField = UITextField()
textField.attributedPlaceholder = NSAttributedString(text: "test Place Holder", color: .gray, font: .systemFont(ofSize: 20))
textField.font = .systemFont(ofSize:10)

 

 

 

원인 

TextField 의 font 속성을 Developer site 에서 찾아보면 

font 는 attributedText 와 attributedPlaceHolder 두개의 속성을 변경한다고 되어있다.

따라서 시점 문제라는 이야기 


developer.apple.com/documentation/uikit/uitextfield/1619604-font

 

Apple Developer Documentation

 

developer.apple.com

 

 

해결

 

단순히 코드의 위치만 조정해주면 해결

textField 의 font 속성 이후에 attributedPlaceHolder 속성을 정의하면 됨

let textField = UITextField()
textField.font = .systemFont(ofSize:10)
textField.attributedPlaceholder = NSAttributedString(text: "test Place Holder", color: .gray, font: .systemFont(ofSize: 20))
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
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 31
글 보관함