-
[UIKit]키보드 위에 수정 제안을 비활성화하기공부/iOS 2023. 12. 13. 19:27
오류 발생 원인
자동으로 맞춤법 교정해주거나 사용자의 입력을 예측해서 입력을 돕는 기능은 유용하지만 때에 따라 필요하지 않는 경우도 존재합니다.
아래의 코드를 textfield에 추가해주면 아래와 같이 제거할 수 있습니다.
textfield.autocorrectionType = .no textfield.spellCheckingType = .no
그러면 다음과 같이 UIKit에서 맞춤법 검사를 무시할 수 있습니다.
코드 사용 예시
import UIKit class PlaneTextField: UITextField { init(placeholder: String) { super.init(frame: .zero) self.placeholder = placeholder self.autocapitalizationType = .none self.autocorrectionType = .no self.spellCheckingType = .no self.borderStyle = .roundedRect } required init?(coder: NSCoder) { fatalError("init(coder:) has not been implemented") } deinit { print("deinitted textfield \(self.placeholder ?? "") \(self.text ?? "")") } }
'공부 > iOS' 카테고리의 다른 글
Xcode15에서 XCTest를 할 때 Testing... 에서 멈추는 현상 (0) 2024.01.02 UIKit에서 Delegate Pattern를 쓰는 이유 (0) 2023.12.21 self에서 unexpected 에러가 발생하는 이유 (0) 2023.12.01 [Swift] Date formatted, FormatStyle로 날짜 출력하기 (0) 2023.07.19 디자인 챌린지 (Asia Pacific) - Part 1 (0) 2023.03.06