iOS 的 UIKit 元件有許多共同與專屬屬性。以下整理常見元件的核心設定,方便開發時快速查閱。
基礎元件
- UIView:可設定 userInteractionEnabled、tag、frame、bounds、center、transform、superview 與 subviews。
- UILabel:常用 text、font、textColor、textAlignment 與 numberOfLines。
- UIImageView:常用 image、animationImages、animationDuration 與 animationRepeatCount。
滾動與列表
- UIScrollView:可設定 contentOffset、contentSize、contentInset、delegate、bounces、pagingEnabled 與縮放範圍。
- UITableView:常用 delegate 與資料來源控制行高、區段與內容。
- UIPickerView:透過 delegate 與資料來源提供滾動選擇資料。
控制項與輸入
- UIControl:可透過 addTarget 監聽點擊、值改變等事件。
- UIDatePicker:可設定 datePickerMode、locale 與 date。
- UISwitch:可透過 on 控制開關狀態。
- UISegmentControl:可取得 selectedSegmentIndex 與 numberOfSegments。
- UISlider:可設定 value、minimumValue 與 maximumValue。
- UIButton:可設定 title、titleColor、image 與 backgroundImage。
- UITextField:常透過 delegate 監聽輸入、送出與編輯狀態。
提示與對話框
UIAlertView 可顯示標題、訊息與按鈕,並透過 delegate 處理點擊。新專案可優先考慮 UIAlertController。