UITextField

Tabber·2021년 7월 13일
0

Apple Document

목록 보기
8/12

Class

An object that displays an editable text area in your interface.
인터페이스에서 편집 가능한 텍스트 영역을 표시하는 개체입니다.

Declaration

class UITextField: UIControl

Overview

You use text fields to gather text-based input from the user using the onscreen keyboard. The keyboard is configurable for many different types of input such as plain text, emails, numbers, and so on. Text fields use the target-action mechanism and a delegate object to report changes made during the course of editing.
텍스트 필드를 사용하여 화면 키보드를 사용하여 사용자의 텍스트 기반 입력을 수집할 수 있습니다. 키보드는 일반 텍스트, 이메일, 숫자 등과 같은 다양한 유형의 입력에 대해 구성할 수 있습니다. 텍스트 필드는 대상 작업 메커니즘과 위임 개체를 사용하여 편집 과정 중에 변경된 내용을 보고합니다.

In addition to its basic text-editing behavior, you can add overlay views to a text field to display additional information and provide additional tappable controls. You might add custom overlay views for elements such as a bookmarks button or search icon. Text fields provide a built-in overlay view to clear the current text. The use of custom overlay views is optional.
기본 텍스트 편집 동작 외에도 텍스트 필드에 오버레이 보기를 추가하여 추가 정보를 표시하고 추가 탭 가능 컨트롤을 제공할 수 있습니다. 북마크 버튼이나 검색 아이콘과 같은 요소에 대한 사용자 지정 오버레이 보기를 추가할 수 있습니다. 텍스트 필드는 현재 텍스트를 지울 수 있는 기본 오버레이 보기를 제공합니다. 사용자 정의 오버레이 보기 사용은 선택 사항입니다.

After adding a text field to your interface, you configure it for use in your app. Configuration involves performing some or all of the following tasks:
텍스트 필드를 인터페이스에 추가한 후 앱에서 사용할 수 있도록 구성합니다. 구성에는 다음 작업의 일부 또는 전부가 포함됩니다.

  • Configure one or more targets and actions for the text field.
    텍스트 필드에 대한 하나 이상의 대상 및 작업을 구성합니다.
  • Configure the keyboard-related attributes of the text field.
    텍스트 필드의 키보드 관련 특성을 구성합니다.
  • Assign a delegate object to handle important tasks, such as:
    위임 개체를 할당하여 다음과 같은 중요한 작업을 처리합니다.
  • Determining whether the user should be allowed to edit the text field’s contents.
    사용자가 텍스트 필드의 내용을 편집할 수 있는지 여부를 결정합니다.
  • Validating the text entered by the user.
    사용자가 입력한 텍스트 유효성 검사.
  • Responding to taps in the keyboard’s return button.
    키보드의 리턴 버튼 누르기에 응답합니다.
  • Forwarding the user-entered text to other parts of your app.
    사용자가 입력한 텍스트를 앱의 다른 부분으로 전달합니다.
  • Store a reference to the text field in one of your controller objects.
    컨트롤러 개체 중 하나에 텍스트 필드에 대한 참조를 저장합니다.

For information about the methods of the text field’s delegate object, see UITextFieldDelegate.
텍스트 필드의 위임 개체 방법에 대한 자세한 내용은 UITextFieldDelegate를 참조하십시오.

Showing and Hiding the Keyboard

When a text field becomes first responder, the system automatically shows the keyboard and binds its input to the text field. A text field becomes the first responder automatically when the user taps it. You can also force a text field to become the first responder by calling its becomeFirstResponder() method. You might force a text field to become first responder when you require the user to enter some information.
텍스트 필드가 최초 응답자가 되면 시스템은 자동으로 키보드를 표시하고 입력 내용을 텍스트 필드에 바인딩합니다. 사용자가 텍스트 필드를 누르면 자동으로 첫 번째 응답자가 됩니다. 또한 첫 번째 응답자() 메서드를 호출하여 텍스트 필드가 첫 번째 응답자가 되도록 할 수도 있습니다. 사용자가 일부 정보를 입력해야 하는 경우 강제로 텍스트 필드가 최초 응답자가 될 수 있습니다.

Note
The appearance of the keyboard has the potential to obscure portions of your user interface. You should update your interface as needed to ensure that the text field being edited is visible. Use the keyboard notifications to detect the appearance and disappearance of the keyboard and to make necessary changes to your interface. For more information, see Responding to Keyboard-Related Notifications.

키보드의 모양은 사용자 인터페이스의 일부를 가릴 수 있습니다. 편집 중인 텍스트 필드가 표시되도록 필요에 따라 인터페이스를 업데이트해야 합니다. 키보드 알림을 사용하여 키보드의 모양과 자취를 감지하고 인터페이스를 필요한 대로 변경합니다. 자세한 내용은 키보드 관련 통지에 대한 응답을 참조하십시오.

You can ask the system to dismiss the keyboard by calling the resignFirstResponder() method of your text field. Usually, you dismiss the keyboard in response to specific interactions. For example, you might dismiss the keyboard when the user taps the keyboard’s return key. The system can also dismiss the keyboard in response to user actions. Specifically, the system dismisses the keyboard when the user taps a new control that does not support keyboard input.
텍스트 필드의 resignFirstResponder() 메서드를 호출하여 시스템에서 키보드를 해제하도록 요청할 수 있습니다. 일반적으로 특정 상호 작용에 대한 응답으로 키보드를 해제합니다. 예를 들어 사용자가 키보드의 반환 키를 누를 때 키보드를 해제할 수 있습니다. 시스템은 사용자 작업에 대한 응답으로 키보드를 해제할 수도 있습니다. 특히 사용자가 키보드 입력을 지원하지 않는 새 컨트롤을 누르면 키보드가 해제됩니다.

The appearance and dismissal of the keyboard affect the editing state of the text field. When the keyboard appears, the text field enters the editing state and sends the appropriate notifications to its delegate. Similarly, when the text field resigns the first responder status, it leaves the editing state and notifies its delegate. For more information about the sequence of events that occur during editing, see Validating Text and Managing the Editing Process.
키보드의 모양과 해제는 텍스트 필드의 편집 상태에 영향을 줍니다. 키보드가 나타나면 텍스트 필드가 편집 상태로 전환되고 대리인에게 적절한 통지를 보냅니다. 마찬가지로 텍스트 필드가 첫 번째 응답자 상태를 다시 시작하면 편집 상태를 종료하고 대리자에게 알립니다. 편집 중에 발생하는 이벤트 순서에 대한 자세한 내용은 텍스트 유효성 검사 및 편집 프로세스 관리를 참조하십시오.

Configuring the Keyboard’s Appearance

You customize your text field’s keyboard using the properties of the UITextInputTraits protocol, which the UITextField class adopts. UIKit supports standard keyboards for the user’s current language and also supports specialized keyboards for entering numbers, URLs, email addresses, and other specific types of information. You use the properties of this protocol to adjust keyboard traits such as the following:
UI 텍스트 필드 클래스가 채택하는 UITextInputTraits 프로토콜의 속성을 사용하여 텍스트 필드의 키보드를 사용자 정의할 수 있습니다. UIKit은 사용자의 현재 언어를 위한 표준 키보드를 지원하며 숫자, URL, 이메일 주소 및 기타 특정 유형의 정보를 입력할 수 있는 특수 키보드도 지원합니다. 이 프로토콜의 속성을 사용하여 다음과 같은 키보드 특성을 조정할 수 있습니다.

  • The type of keyboard to display
    표시할 키보드 유형
  • The autocapitalization behavior of the keyboard
    키보드의 자동 대문자화 동작
  • The autocorrection behavior of the keyboard
    키보드의 자동 보정 동작
  • The type of return key to display
    표시할 리턴 키의 유형

For information about how to configure keyboard attributes in Interface Builder or in your code, see Table 2.
Interface Builder 또는 사용자 코드에서 키보드 특성을 구성하는 방법에 대한 자세한 내용은 표 2를 참조하십시오.

Because the system manages the showing and hiding of the keyboard in response to responder changes, it posts the following notifications for tracking the keyboard-related changes:
응답자 변경에 대응하여 키보드의 표시 및 숨기기를 관리하는 시스템은 키보드 관련 변경 사항을 추적하기 위해 다음과 같은 알림을 게시합니다.

  • keyboardWillShowNotification
  • keyboardDidShowNotification
  • keyboardWillHideNotification
  • keyboardDidHideNotification
  • keyboardWillChangeFrameNotification
  • keyboardDidChangeFrameNotification

Each notification contains a userInfo dictionary that includes the size of the keyboard. Because the keyboard can hide portions of your interface, you should use the size information to reposition your content on the screen. For content embedded in a scroll view, you can scroll the text field into view, as illustrated in Figure 2. In other cases, you can resize your main content view so that it is not covered by the keyboard.
각 알림에는 키보드 크기를 포함하는 userInfo 사전이 포함됩니다. 키보드는 인터페이스의 일부를 숨길 수 있으므로 크기 정보를 사용하여 화면에서 콘텐츠의 위치를 변경해야 합니다. 스크롤 보기에 포함된 내용의 경우, 그림 2에 나온 것처럼 텍스트 필드를 보기 안으로 스크롤할 수 있습니다. 또는 키보드에서 다루지 않도록 기본 컨텐츠 보기의 크기를 조정할 수 있습니다.

Figure 2 Adjusting the position of a text field when the keyboard appears

For more information about managing keyboard interactions, see Text Programming Guide for iOS.
키보드 상호 작용 관리에 대한 자세한 내용은 iOS용 텍스트 프로그래밍 가이드를 참조하십시오.

Formatting the Text in a Text Field

There are two types of formatting you can do to a text field’s text:
텍스트 필드의 텍스트에 대해 수행할 수 있는 형식 지정에는 두 가지 유형이 있습니다.

  • You can change the font, color, and style of the text using properties of this class. Alternatively, you can specify an NSAttributedString for the text field’s content.
    이 클래스의 속성을 사용하여 텍스트의 글꼴, 색상 및 스타일을 변경할 수 있습니다. 또는 텍스트 필드의 컨텐츠에 대한 NSATributedString을 지정할 수 있습니다.

  • You can format the content of a text field using an Formatter object.
    Formatter 개체를 사용하여 텍스트 필드의 내용을 포맷할 수 있습니다.

The font, textColor, and textAlignment properties, among others, affect the appearance of the text field’s string. Modifying these properties applies the specified characteristic to the entire string. To specify more granular formatting, specify the text field’s text using an NSAttributedString object.
글꼴, 텍스트 색상 및 텍스트 정렬 속성은 텍스트 필드의 문자열 모양에 영향을 줍니다. 이러한 속성을 수정하면 지정된 특성이 전체 문자열에 적용됩니다. 보다 세분화된 형식을 지정하려면 NSATripedString 개체를 사용하여 텍스트 필드의 텍스트를 지정하십시오.

The UITextField class does not provide built-in support for formatting its string using an Formatter object, but you can use the text field’s delegate to format the content yourself. To do so, use the text field’s delegate methods to validate text and to format it appropriately. For example, use the textField(_:shouldChangeCharactersIn:replacementString:) method to validate and format text while the user is typing. For information about how to use formatter objects, see Data Formatting Guide.

UITextField 클래스는 Formatter 개체를 사용하여 문자열을 포맷할 수 있도록 기본적으로 지원하지는 않지만 텍스트 필드의 대리자를 사용하여 내용을 직접 포맷할 수 있습니다. 이렇게 하려면 텍스트 필드의 위임 방법을 사용하여 텍스트를 검증하고 형식을 적절하게 지정하십시오. 예를 들어 textField(_:shouldChangeCharactersIn:replaceString:) 메서드를 사용하여 사용자가 입력하는 동안 텍스트를 검증하고 형식을 지정합니다. 포맷기 개체 사용 방법에 대한 자세한 내용은 데이터 포맷 가이드를 참조하십시오.

profile
iOS 정복중인 Tabber 입니다.

0개의 댓글