Notice
Recent Posts
Recent Comments
Link
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 |
Tags
- scrollview
- 애니메이션
- Human interface guide
- 리팩토링
- map
- 리펙토링
- ios
- collectionview
- Protocol
- 클린 코드
- UICollectionView
- UITextView
- swift documentation
- tableView
- RxCocoa
- Xcode
- rxswift
- SWIFT
- combine
- ribs
- MVVM
- clean architecture
- uitableview
- uiscrollview
- Clean Code
- Observable
- swiftUI
- Refactoring
- 스위프트
- HIG
Archives
- Today
- Total
김종권의 iOS 앱 개발 알아가기
[iOS - swift] UITextInputDelegate 개념 (UITextView, UITextField) 본문
iOS 응용 (swift)
[iOS - swift] UITextInputDelegate 개념 (UITextView, UITextField)
jake-kim 2023. 11. 15. 01:26UITextInputDelegate 개념
- 텍스트 입력에 대한 델리게이트
- UITextView와 UITextField가 가지고 있는 delegate

- iOS 3.2+에서 제공

- 코드로는 inputDelegate로 접근
- selectionWillChange: textFIeld나 textView 글자를 눌러서 선택했을때 바로 직전 호출
- selectionDidChange: textFIeld나 textView 글자를 눌러서 선택하거나 드래그했을때 selected range값이 업데이트된 후 호출
- 주의) text 자체가 change되는 이벤트들은 문서와는 다르게 실제로 코딩해보면 호출 x
- textWillChnage: text가 변경되기 직전 호출
- textDidChnage: text가 변경되고난 후 호출
textField.inputDelegate = self
extension ViewController: UITextInputDelegate {
func selectionWillChange(_ textInput: UITextInput?) {
print("selectionWillChange")
}
func selectionDidChange(_ textInput: UITextInput?) {
print("selectionDidChange")
}
func textWillChange(_ textInput: UITextInput?) {
print("textWillChange")
}
func textDidChange(_ textInput: UITextInput?) {
print("textDidChange")
}
}
테스트)

* 전체 코드: https://github.com/JK0369/ExTextInputDelegate
* 참고
https://developer.apple.com/documentation/uikit/uitextinputdelegate
'iOS 응용 (swift)' 카테고리의 다른 글
Comments