UIPickerView是iOS中的原生選擇器控件,使用方便,用法簡(jiǎn)單,效果漂亮。
注意:showsSelectionIndicator選擇欄屬性在iOS7之后貌似沒有任何效果
@property(nonatomic,assign) id<UIPickerViewDataSource> dataSource;
@property(nonatomic,assign) id<UIPickerViewDelegate> delegate;
// 設(shè)置數(shù)據(jù)源和代理
@property(nonatomic) BOOL showsSelectionIndicator;
// 是否顯示選擇框,在iOS7之后這個(gè)屬性沒有任何效果
@property(nonatomic,readonly) NSInteger numberOfComponents;
// 獲取分區(qū)數(shù)
- (NSInteger)numberOfRowsInComponent:(NSInteger)component;
// 獲取某一分區(qū)的行數(shù)
- (CGSize)rowSizeForComponent:(NSInteger)component;
// 獲取某一分區(qū)行的尺寸
- (UIView *)viewForRow:(NSInteger)row forComponent:(NSInteger)component;
// 獲取某一分區(qū)某一行的視圖
- (void)reloadAllComponents;
// 重載所有分區(qū)
- (void)reloadComponent:(NSInteger)component;
// 重載某一分區(qū)
- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated;
// 設(shè)置選中某一分區(qū)某一行
- (NSInteger)selectedRowInComponent:(NSInteger)component;
// 返回某一分區(qū)選中的行
// 數(shù)據(jù)源代理中的方法:
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
// 設(shè)置分區(qū)數(shù)
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
// 根據(jù)分區(qū)設(shè)置行數(shù)
// 代理中的方法:
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component;
// 設(shè)置分區(qū)寬度
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component;
// 設(shè)置分區(qū)行高
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
// 設(shè)置某一行顯示的標(biāo)題
- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component;
// 通過屬性字符串設(shè)置某一行顯示的標(biāo)題
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view;
// 設(shè)置某一行顯示的view視圖
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;
// 選中某一行時(shí)執(zhí)行的回調(diào)