// 數(shù)據(jù)源(用來告訴UIPickerView有多少列多少行)
@property(nonatomic,assign) iddataSource;
// 代理(用來告訴UIPickerView每1列的每1行顯示什么內(nèi)容,監(jiān)聽UIPickerView的選擇)
@property(nonatomic,assign) iddelegate;
// 是否要顯示選中的指示器
@property(nonatomic) BOOL showsSelectionIndicator;
// 一共有多少列
@property(nonatomic,readonly) NSInteger numberOfComponents;
2.UIPickerView的常見方法
// 重新刷新所有列
- (void)reloadAllComponents;
// 重新刷新第component列
- (void)reloadComponent:(NSInteger)component;
// 主動選中第component列的第row行
- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated;
// 獲得第component列的當(dāng)前選中的行號
- (NSInteger)selectedRowInComponent:(NSInteger)component;
3.數(shù)據(jù)源方法(UIPickerViewDataSource)
// 一共有多少列
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
// 第component列一共有多少行
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
4.代理方法(UIPickerViewDelegate)
// 第component列的寬度是多少
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component;
// 第component列的行高是多少
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component;
// 第component列第row行顯示什么文字
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
// 第component列第row行顯示怎樣的view(內(nèi)容)
// 這個方法的reusingView在ios6之后就一直為空鸵闪。如果需要適配ios6之前的系統(tǒng)紊扬,為了性能考慮膨桥,應(yīng)該將這個view利用起來聋迎。
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view;
// 選中了pickerView的第component列第row行
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;
二.UIDatePicker
1.常見屬性
// datePicker的顯示模式
@property (nonatomic) UIDatePickerMode datePickerMode;
// 顯示的區(qū)域語言
@property (nonatomic, retain) NSLocale *locale;
2.監(jiān)聽UIDatePicker的選擇
- 因為UIDatePicker繼承自UIControl,所以通過addTarget:...監(jiān)聽
3.代碼創(chuàng)建UIDatePicker
// 1.創(chuàng)建日期選擇器
UIDatePicker *datePicker = [[UIDatePicker alloc] init];
// 2.設(shè)置日期顯示區(qū)域
datePicker.locale = [NSLocale localeWithLocaleIdentifier:@"zh"];
// 3.設(shè)置日期模式
datePicker.datePickerMode = UIDatePickerModeTime;
// 4.0 設(shè)置最小時間(從當(dāng)前時間起的前20年)
datePicker.minimumDate = [NSDate dateWithTimeIntervalSinceNow:-(365 * 24 * 3600 * 20)];
// 4.1 設(shè)置最大時間(從當(dāng)前時間起的后20年)
datePicker.maximumDate = [NSDate dateWithTimeIntervalSinceNow:365 * 24 * 3600 * 20];
// 5.設(shè)置時間間隔。(該間隔要能夠讓60整除)
datePicker.minuteInterval = 6;