pickerView는 label이나 button처럼 손쉽게 텍스트에 대한 접근을 할 수 없다.
생긴것부터가 배열이니 배열 전체에 대해 어떻게 해줄까를 정해줘야되서 그렇게 해둔듯 하다.
그러한 부분을 어떻게 할지를 정하는 함수가 pickerview에는 있다.
func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString?
라는 함수 인데
텍스트를 그냥 넣어 줄때 사용하는
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String?
와 사용이 비슷하다.
아래는 빨간색으로 변경하는 예시를 플레이그라운드에서 만들어 보았다.
텍스트 설정을 변경하는 키값이 상당히 많은데 그중에서도
를 사용했다.
위 소스를 플레이그라운드에서 돌리면 아래와 같이 나온다.
아래는 키들에 대한 애플문서이다.
https://developer.apple.com/documentation/foundation/nsattributedstring/key
반응형
'iOS > swift' 카테고리의 다른 글
KeyboardObserver~ (0) | 2021.10.19 |
---|---|
Guide Swift Programming Language 5.5 (0) | 2021.10.01 |
프로그래머스 - 프린터 (0) | 2021.05.06 |
프로그래머스 - 기능개발 (0) | 2021.05.05 |
프로그래머스 - 모의고사 (0) | 2021.05.04 |