iOS UIKit框架学习—UIPickerView

UIPickerView 类实现对象,称为选取器视图,用纺车或老虎机的隐喻来显示一个或多个集合的值。用户通过旋转的车轮,以便与选择指示器对齐所需的行的值来选择值

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
@protocol UIPickerViewDataSource, UIPickerViewDelegate;
NS_CLASS_AVAILABLE_IOS(2_0) __TVOS_PROHIBITED @interface UIPickerView : UIView <NSCoding>
// 数据源
@property(nullable,nonatomic,weak) id<UIPickerViewDataSource> dataSource;
// 代理
@property(nullable,nonatomic,weak) id<UIPickerViewDelegate> delegate;
// 是否显示选择指示符
@property(nonatomic) BOOL showsSelectionIndicator; // default is NO
// 获取该选择视图组件的数量
@property(nonatomic,readonly) NSInteger numberOfComponents;
// 返回组件的行数
- (NSInteger)numberOfRowsInComponent:(NSInteger)component;
// 返回组件行的大小
- (CGSize)rowSizeForComponent:(NSInteger)component;
// 返回指定行和控件的视图控制器
- (nullable UIView *)viewForRow:(NSInteger)row forComponent:(NSInteger)component;
// 刷新单一视图组件或全部
- (void)reloadAllComponents;
- (void)reloadComponent:(NSInteger)component;
// 将指定的行滚动到选择器中心
- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated;
// 返回选定的组件的下标
- (NSInteger)selectedRowInComponent:(NSInteger)component;
@end
__TVOS_PROHIBITED
@protocol UIPickerViewDataSource<NSObject>
@required
// 返回要显示列的数目
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
// 返回指定选择器的组件的行数
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
@end
__TVOS_PROHIBITED
@protocol UIPickerViewDelegate<NSObject>
@optional
// 返回组件列的宽度和高度
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component __TVOS_PROHIBITED;
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component __TVOS_PROHIBITED;
// 给组件设置标题
- (nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component __TVOS_PROHIBITED;
// 给组件设置带样式的标题
- (nullable NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component NS_AVAILABLE_IOS(6_0) __TVOS_PROHIBITED;
// 设置指定的行指定组件的视图
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(nullable UIView *)view __TVOS_PROHIBITED;
// 用户选择组件中的行时调用
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component __TVOS_PROHIBITED;
@end