이끼의 생각

[iOS Swift] 키보드 종류, Textfield 본문

Mobile App/iOS와 Swift

[iOS Swift] 키보드 종류, Textfield

IKKIson 2019. 4. 18. 10:06

iOS에서 Textfield 같은 UI구성요소에서 입력을 할 때 Textfield를 터치하면 키보드가 밑에서 띄워진다.

 

키보드로 입력을 할때 숫자만 입력해야되거나 URL입력, 이메일 입력 등 목적에 알맞은 키보드를 설정해줘야 사용자가 원하는 키보드로 매번 바꾸지않고 보다 편리하게 입력을 할 수 있게 된다. 

즉, 의도에 알맞게 키보드의 종류를 바꿀 수 있다.

 

KeyboardType에서 키보드 설정을 확인할 수 있다. 

KeyboardType은 Apple Developer 페이지에서 Documentation/UIKit/Keyboards and Input/KeyboardType 에서 확인할 수 있다.

https://developer.apple.com/documentation/uikit/uitextinputtraits/1624457-keyboardtype

 

keyboardType - UITextInputTraits | Apple Developer Documentation

Instance Property keyboardType The keyboard style associated with the text object. DeclarationDiscussionText objects can be targeted for specific types of input, such as plain text, email, numeric entry, and so on. The keyboard style identifies what keys a

developer.apple.com

typedef enum {
	case `default`
	Specifies the default keyboard for the current input method.
	
	case asciiCapable
	Specifies a keyboard that displays standard ASCII characters.
	
	case numbersAndPunctuation
	Specifies the numbers and punctuation keyboard.
	
	case URL
	Specifies a keyboard optimized for URL entry. This keyboard type prominently features the period (“.”) and slash (“/”) characters and the “.com” string.
	
	case numberPad
	Specifies a numeric keypad designed for PIN entry. This keyboard type prominently features the numbers 0 through 9. This keyboard type does not support auto-capitalization.
	
	case phonePad
	Specifies a keypad designed for entering telephone numbers. This keyboard type prominently features the numbers 0 through 9 and the “*” and “#” characters. This keyboard type does not support auto-capitalization.
	
	case namePhonePad
	Specifies a keypad designed for entering a person’s name or phone number. This keyboard type does not support auto-capitalization.
	
	case emailAddress
	Specifies a keyboard optimized for entering email addresses. This keyboard type prominently features the at (“@”), period (“.”) and space characters.
	
	case decimalPad
	Specifies a keyboard with numbers and a decimal point.
	
	case twitter
	Specifies a keyboard optimized for Twitter text entry, with easy access to the at (“@”) and hash (“#”) characters.
	
	case webSearch
	Specifies a keyboard optimized for web search terms and URL entry. This keyboard type prominently features the space and period (“.”) characters.
	
	case asciiCapableNumberPad
	Specifies a number pad that outputs only ASCII digits.
}UIKeyboardType;
static var alphabet: UIKeyboardType
Specifies a keyboard optimized for alphabetic entry.

 

default : 기본적인 키보드

ASCIICapable : 영문만 표시되는 키보드

NumbersAndPunctuation : 숫자와 특수문자가 표시되는 키보드

URL : URL을 입력할 수 있도록 .과 / 그리고 .com이 키보드 영역에 표시되는 키보드

NumberPad : 숫자를 입력하는 키패드 형식의 키보드

PhonePad : 전화 번호를 입력할 수 있는 키패드 형식의 키보드

NamePhonePad : 대문자 입력이 불가한 키보드

EmailAddress : 이메일을 입력할 수 있도록 @와 .이 키보드 영역에 표시되는 키보드

DecimalPad : 소숫점을 입력할 수 있는 키패드 형식의 키보드

Twitter : 트위터 입력을 빠르게 할 수 있도록 @와 #이 추가된 키보드

WebSearch : URL 및 검색어 입력에 최적화 됨 (공백 및. 표시)

Alphabet = ASCIICapable : 더 이상 사용 안함

 

생성한 TextField Outlet변수에 위의 원하는 속성을 정해주면된다.

ex)

textField01.keyboardType = .done
textField02.keyboardType = .default
Comments