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

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

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;


选中某一行时执行的回调

目录
相关文章
|
JSON 自然语言处理 Dart
Alibaba.com瘦包40MB——业界最全的iOS包大小技术总结
本文总结提炼了Alibaba.com App的瘦身的技术和策略,系统化地介绍APP瘦身的业务价值、分析技术、瘦身技术、防劣化机制,让读者可以系统化地了解APP瘦身的技术体系。并基于实践经验,介绍各种瘦身技术的ROI,让读者可以避免踩雷,将资源浪费在效果不佳的技术上。希望对你有所帮助。
Alibaba.com瘦包40MB——业界最全的iOS包大小技术总结
|
10月前
|
iOS开发
iOS 多个滚动控件嵌套Demo
iOS 多个滚动控件嵌套Demo
47 0
|
10月前
|
iOS开发
iOS 常用的 上下左右 拉刷新控件
iOS 常用的 上下左右 拉刷新控件
57 0
|
iOS开发
iOS短信验证码控件,自动输入回调两次解决办法
iOS短信验证码控件,自动输入回调两次解决办法
369 0
|
iOS开发
IOS的UITableView控件简单使用
IOS的UITableView控件简单使用
134 0
|
iOS开发
iOS开发 - 写一个刷新的控件(未封装,适合新手学习,查看原理)
iOS开发 - 写一个刷新的控件(未封装,适合新手学习,查看原理)
134 0
iOS开发 - 写一个刷新的控件(未封装,适合新手学习,查看原理)
|
iOS开发
iOS开发 - 滚动选择器
iOS开发 - 滚动选择器
190 0
iOS开发 - 滚动选择器
|
安全 iOS开发
iOS小技能:下拉刷新控件的适配
1. 下拉顶部背景色设置: 往tableView的父控件添加拉伸背景视图 2. present 半屏适配 iOS13 modalPresentationStyle属性默认不是全屏样式`UIModalPresentationFullScreen`,而是半屏样式,需要根据需求手动设置。 present 半屏,会导致列表下拉刷新失效。
174 0
iOS小技能:下拉刷新控件的适配
|
iOS开发
iOS小技能:自动布局实现兄弟控件N等分且宽高比例是1:N(xib 上实现)
本文为 iOS视图约束专题的第三篇:xib上使用自动布局教程
153 0
|
自然语言处理 Java C#
浅谈 Unity、iOS、Android 闭包的使用方法
浅谈 Unity、iOS、Android 闭包的使用方法
220 0
浅谈 Unity、iOS、Android 闭包的使用方法