UIPickerView

選擇器

初始化就沒必要了,列一些常用屬性;

屬性
//顯示選中框  
pickerView.showsSelectionIndicator=YES;  

// 數(shù)據(jù)源
pickerView.dataSource=self;  

// 代理
pickerView.delegate=self;  

// 一共有多少列  (只讀)
pickerView.numberOfComponents;  

// 一共有多少行(只讀)  
pickerView. numberOfRowsInComponent;  
常用方法
//獲取某一列的行數(shù)
- (NSInteger)numberOfRowsInComponent:(NSInteger)component;

//獲取某一列行的Size
- (CGSize)rowSizeForComponent:(NSInteger)component;

//返回第component列,第row行的控件。
- (nullable UIView *)viewForRow:(NSInteger)row forComponent:(NSInteger)component;

// 更新某一列 和 更新全部
- (void)reloadComponent:(NSInteger)component;
- (void)reloadAllComponents;

//動(dòng)畫效果跳到選中某一列的某一行
- (void)selectRow:(NSInteger)row inComponent:(NSInteger)component animated:(BOOL)animated;

//返回某一列的選中行,-1表示沒有選中行
- (NSInteger)selectedRowInComponent:(NSInteger)component;                                   

代理方法
//  第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)容)  
- (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;  
數(shù)據(jù)源方法
//  一共有多少列  
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;  

//  第component列一共有多少行  
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;  
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容