iOS選擇器視圖控件(UIPickerView)使用方法總結

iOS中UIPickerView使用總結

UIPickerView是iOS中的原生選擇器控件,使用方便,用法簡單,效果漂亮。atom

 

@property(nonatomic,assign) id<UIPickerViewDataSource> dataSource;                spa

@property(nonatomic,assign) id<UIPickerViewDelegate>   delegate; .net

設置數據源和代理3d

@property(nonatomicBOOL showsSelectionIndicator;代理

是否顯示選擇框,在iOS7以後這個屬性沒有任何效果component

 

@property(nonatomic,readonly) NSInteger numberOfComponents;字符串

獲取分區數get

 

- (NSInteger)numberOfRowsInComponent:(NSInteger)component;it

獲取某一分區的行數io

 

- (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;

選中某一行時執行的回調

專一技術,熱愛生活,交流技術,也作朋友。

——琿少 QQ羣:203317592

相關文章
相關標籤/搜索