The target object—that is, the object whoseactionmethod is called. If you specifynil, UIKit searches the responder chain for an object that responds to the specified action message and delivers the message to that object.
action
A selector identifying the action method to be called. You may specify a selector whose signature matches any of the signatures inListing 1. This parameter must not benil.
controlEvents
A bitmask specifying the control-specific events for which the action method is called. Always specify at least one constant. For a list of possible constants, seeUIControl.Event.
You may call this method multiple times to configure multiple targets and actions for the control. It is also safe to call this method multiple times with the same values for thetargetandactionparameters. The control maintains a list of its attached targets and actions along with the events each supports.
The control does not retain the object in thetargetparameter. It is your responsibility to maintain a strong reference to the target object while it is attached to a control.
Specifying a value of0for thecontrolEventsparameter does not prevent events from being sent to a previously registeredtargetandactionmethod. To stop the delivery of events, always call theremoveTarget(_:action:for:)method.
🔹 UISwitch
- 정의 : On/Off 상태를 표시하고 전환하는 데 사용되는 UI 요소
- 주요 속성 : isOn, onTintColor, thumbThintColor, addTarget(_:action:for:)
- 정의 : 여러 개의 세그먼트로 구성된 컨트롤로, 각 세그먼트를 선택하여 원하는 옵션을 선택할 수 있는 UI 요소 (User interection ⭕️ )
- 예시 : 탭 바, 네비게이션 바
- 주요 속성 : selectedSegmentIndex, numberOfSegments, tintColor, isMomentary
isMomentary : 선택 표시를 유지할지 여부
false : 선택 표시 유지함
true : 선택 표시 유지 안함(momentary)
🔹 UIScrollView
- 정의 : 화면에서 스크롤 가능한 영역을 제공하는 UI 요소
- 주요 속성 : contentSize, contentOffset, contentInset, isScrollEnabled, isPagingEnabled, bounces
페이지 기능
isPagingEnabled = false
isPagingEnabled = true
🔹 UIPickerView
- 정의 : 사용자가 여러 개의 옵션 중 하나를 선택할 수 있는 회전 가능한 휠 형식의 UI 요소
- 주요 속성 : dataSource, delegate, numberOfComponents, selectedRow(inComponent:)
// class에서 UIViewController에 더해UIPickerViewDelegate, UIPickerViewDataSource를 추가로 상속
// 코드
결과
UIView
프린트된 것
🔹 UITableView
- 정의 : 데이터 목록을 표시하고 사용자와 상호작용할 수 있는 스크롤 가능한 UI 요소
- 주요 속성 :
dataSource: UITableView의 데이터를 제공하는 객체를 설정합니다. delegate: UITableView의 이벤트를 처리하는 객체를 설정합니다. rowHeight: 각 행의 높이를 설정합니다. separatorStyle: 행 간 구분선의 스타일을 설정합니다. separatorColor: 행 간 구분선의 색상을 설정합니다. allowsSelection: 테이블 뷰에서 행 선택을 허용할지 여부를 설정합니다.
// class에서 UIViewController에 더해 UITableViewDelegate, UITableViewDataSource를 추가로 상속
// 코드
tableView.deselectRow(at:animated:) : 터치 해제 시 음영 제거하는 기능
deselect O
deselect X
🔹 UICollectionView
- 정의 : 유연한 그리드 레이아웃을 사용하여 아이템 목록을 표시하고 사용자와 상호작용할 수 있는 스크롤 가능한 UI 요소
- 예시 : 사진첩
- 주요 속성 : dataSource, delegate, collectionViewLayout, allowsSelection, allowsMultipleSelection
// class에서 UIViewController에 더해 UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout를 추가로 상속