標籤:
iOS中UIPickerView使用總結
UIPickerView是iOS中的原生選取器控制項,使用方便,用法簡單,效果漂亮。
@property(nonatomic,assign) id<UIPickerViewDataSource> dataSource;
@property(nonatomic,assign) id<UIPickerViewDelegate> delegate;
設定資料來源和代理
@property(nonatomic) BOOL showsSelectionIndicator;
是否顯示選擇框,在iOS7之後這個屬性沒有任何效果
@property(nonatomic,readonly) NSInteger numberOfComponents;
擷取分區數
- (NSInteger)numberOfRowsInComponent:(NSInteger)component;
擷取某一分區的行數
- (CGSize)rowSizeForComponent:(NSInteger)component;
擷取某一分區行的尺寸
- (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;
返回某一分區選中的行
資料來源代理中的方法:
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
設定分區數
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
根據分區設定行數
代理中的方法:
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component;
設定分區寬度
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component;
設定分區行高
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
設定某一行顯示的標題
- (NSAttributedString *)pickerView:(UIPickerView *)pickerView attributedTitleForRow:(NSInteger)row forComponent:(NSInteger)component;
通過屬性字串設定某一行顯示的標題
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view;
設定某一行顯示的view視圖
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;
選中某一行時執行的回調
iOS選取器視圖控制項(UIPickerView)使用方法總結