UIPickerView

选择器

初始化就没必要了,列一些常用属性;

属性
//显示选中框  
pickerView.showsSelectionIndicator=YES;  

// 数据源
pickerView.dataSource=self;  

// 代理
pickerView.delegate=self;  

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

// 一共有多少行(只读)  
pickerView. numberOfRowsInComponent;  
常用方法
//获取某一列的行数
- (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;

//动画效果跳到选中某一列的某一行
- (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(内容)  
- (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;  
数据源方法
//  一共有多少列  
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;  

//  第component列一共有多少行  
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;  
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容