前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >iOS选择器视图控件(UIPickerView)使用方法总结

iOS选择器视图控件(UIPickerView)使用方法总结

作者头像
珲少
发布2018-08-15 15:06:41
1.2K0
发布2018-08-15 15:06:41
举报
文章被收录于专栏:一“技”之长

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;

选中某一行时执行的回调

专注技术,热爱生活,交流技术,也做朋友。 ——珲少 QQ群:203317592

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2015/06/10 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • iOS中UIPickerView使用总结
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档