๋ฐ์ํ
์๋ ํ์ธ์~
์ค๋์ UITextField์ Placeholder์
ํ ์คํธ ์ปฌ๋ฌ๋ฅผ ์กฐ์ ํ๋ ๋ฐฉ๋ฒ์ ๋ํด์ ์ ๋ฆฌํ๋ ค๊ณ ํฉ๋๋ค : )
TextField์ ์ ๊ทผํ์ฌ placeholder์
ํ ์คํธ ์ปฌ๋ฌ๋ฅผ ๋ณ๊ฒฝํ ์ ์๋ ๋ฉ์๋๋ ํ๋กํผํฐ๊ฐ ์กด์ฌํ์ง ์์ต๋๋ค.
๋ฐ๋ผ์ ์๋์ ๊ฐ์ด ์์ฑํ๋ฉด ํด๊ฒฐ์ด ๊ฐ๋ฅํฉ๋๋ค.
1. ํ ์คํธ ํ๋ ์ ์ธ
private let myTextField: UITextField = UITextField()
2. ํ ์คํธ ํ๋์ attributedPlaceholder ํ๋กํผํฐ์ ์ ๊ทผ ๋ฐ ์ํ๋ ์ปฌ๋ฌ๋ก ์ค์
myTextField.attributedPlaceholder = NSAttributedString(string: "๋์ ์ปฌ๋ฌ๋ ํน๋ณํ์ง", attributes: [NSAttributedString.Key.foregroundColor : UIColor.green])
๊ทธ๋ฌ๋ฉด ์ง์ ํ ์ปฌ๋ฌ๋ก placeholder์ ์ปฌ๋ฌ๋ฅผ ๋ณ๊ฒฝํ ์ ์๊ฒ ๋ฉ๋๋ค : )
[ ์ฐธ๊ณ ]
์์์ ๋์จ NSAttributedString์ ์์ฑ์๋ฅผ ์ฐพ์๋ณด๋ฉด
public init(string str: String, attributes attrs: [NSAttributedString.Key : Any]? = nil)
attributes๋ผ๋ key์ value๋ฅผ ์ค์ ํ ์ ์๋ ์์ฑ์๊ฐ ์์ต๋๋ค.
์ด๋ฅผ ์ด์ฉํด ๋ค์ํ ํค - ๋ฐธ๋ฅ๋ฅผ ์กฐ์ ํ ์ ์์ด์ ํฐํธ, ๋ฐฑ๊ทธ๋ผ์ด๋ ์ปฌ๋ฌ, ๋งํฌ ๋ฑ๋ฑ์ ์ค์ ํ ์ ์๋ค๊ณ ํฉ๋๋ค.
๋ฐ์ํ