Xcode/UIkit
[Swift] UITextField 디자인 코드 모음집
iOS조이킴
2024. 5. 22. 21:44
안녕하세요 조이킴입니다. 🐥
이 페이지에는 UITextField의 디자인 구현과 관련한 내용을 모아두고 있습니다.
Placeholder 미리보기 텍스트
// placeholder text
textField.placeholder = "원하는 문구 입력"
// placeholder textColor
textField.attributedPlaceholder = NSAttributedString(string: placeholder, attributes: [.foregroundColor : UIColor.lightGray])
borderStyle 테두리
// 테두리 모양
textField.borderStyle = .none // 테두리 없음
textField.borderStyle = .line // 입체갑없는 사각 테두리
textField.borderStyle = .bezel // 입체감있는 사각 테두리
textField.borderStyle = .roundedRect //둥근 테두리
입력창
// 입력창 사이즈
textField.frame.size.height = 48
// 입력창 색깔
textField.backgroundColor = .clear // 투명
// 커서 색깔
textField.tintColor = .clear // 투명
유용한 설정
// 입력 시 사용할 키보드 타입
textField.keyboardType = UIKeyboardType.emailAddress
// 자동 대문자 변환
textField.autocapitalizationType.sentences = .none // 문장 첫글자만
textField.autocapitalizationType.allChracters = .none // 모든 문자
// 자동 수정 기능
textField.autocorrectionType = .no
// 자동 맞춤법 체크
textField.spellCheckingType = .no
// 텍스트 보안 설정 (* 문자로 대체하여 표시 - 비밀번호 입력되는 즉시 가리기 )
textField.isSecureTextEntry = true
// 입력 시작 시 기존 텍스트 전체 삭제
textField.clearsOnBeginEditing = false
// 입력값 한번에 지우는 버튼
textField.clearButtonMode = .always // 항상 보이게
// 입력값 제출 버튼 타입
textField.returnKeyType = .next
// 입력 시작 시 제출(리턴)키 활성화
textField.enablesReturnKeyAutomatically = true
반복 사용되는 뷰, 아직도 일일이 코드 치고 계신가요....??? 🐤
2024.06.23 - [Xcode/UIkit] - [swift] CustomView 커스텀뷰객체 재활용 - 뷰 작업 시간 단축하기