给iOS开发新手送点福利,简述UIPikerView的属性和用法
1. numberOfComponents:返回UIPickerView当前的列数
NSInteger num = _pickerView.numberOfComponents;
NSLog( @"%d", num);
2. - (NSInteger)numberOfRowsInComponent:(NSInteger)component; 返回component列中有多少行。
NSInteger numInCp = [_pickerView numberOfRowsInComponent:0];
NSLog(@"%d",numInCp);
3. - (CGSize)rowSizeForComponent:(NSInteger)component; 返回component中一行的尺寸。
CGSize size = [_pickerView rowSizeForComponent:0];
NSLog(@"%@", NSStringFromCGSize(size));

2. delegate:
2.0 设置UIPickerView代理
_pickerView.delegate = self;
// 设置UIPickView每行显示的内容
2.1 - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return @"showData";
}

2.2 - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view;
// 返回一个视图,用来设置pickerView的每行显示的内容。
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
UIView *myView=[[UIView alloc]init];
myView.backgroundColor = [UIColor redColor];
return myView;
}
效果:

3. dataSource:数据源
#pragma mark - dataSource method
// 设置每列显示3行
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return 3;
}
// 设置显示2列
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 2;
}
4. showsSelectionIndicator:是否显示指示器,默认为NO
_pickerView.showsSelectionIndicator = NO;
注意:设置UIPickerView的行数与列数需要设置数据源,遵守UIPickerViewDataSource,设置UIPickerView的内容需要设置代理,并且遵守代理方法UIPickerViewDelegate。

5.-(void)pickerView:(UIPickerView*)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component;
当点击UIPickerView的某一列中某一行的时候,就会调用这个方法。
6. 返回第component列每一行的高度
- (CGFloat)pickerView:(UIPickerView *)pickerView
rowHeightForComponent:(NSInteger)component;
7.刷新某一列的数据
一旦调用了这个方法,就会重新给数据源发送消息计算这列的行数、重新给代理发送消息获得这列的内容
[pickerView reloadComponent:1];
8. 刷新所有列的数据
- (void)reloadAllComponents;
9. 返回选中的是第component列的第几行。
- (NSInteger)selectedRowInComponent:(NSInteger)component;
给iOS开发新手送点福利,简述UIPikerView的属性和用法的更多相关文章
- 给iOS开发新手送点福利,简述UIImagePickerController的属性和用法
1.+(BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType; // 检查指定源是否在设备上 ...
- 给iOS开发新手送点福利,简述UITableView的属性和用法
UITableView UITableView内置了两种样式:UITableViewStylePlain,UITableViewStyleGrouped <UITableViewDataSo ...
- 给iOS开发新手送点福利,简述UIView的属性和用法
UIView 1.alpha 设置视图的透明度.默认为1. // 完全透明 view.alpha = 0; // 不透明 view.alpha = 1; 2.clipsToBounds // 默认是N ...
- 给iOS开发新手送点福利,简述UITextField的属性和用法
UITextField属性 0. enablesReturnKeyAutomatically 默认为No,如果设置为Yes,文本框中没有输入任何字符的话,右下角的返回按钮是disabled的. ...
- 给iOS开发新手送点福利,简述UILabel的属性和用法
UILabel属性 1.text:设置标签显示文本. label.text = @"我是Label"; 2.attributedText:设置标签属性文本. NSString *t ...
- 给iOS开发新手送点福利,简述UIScrollView的属性和用法
UIScrollView 1. contentOffset 默认CGPointZero,用来设置scrollView的滚动偏移量. // 设置scrollView的滚动偏移量 scrollView ...
- 给iOS开发新手送点福利,简述UIPageControl的属性和用法
UIPageControl 1. numberOfPages // 设置有多少页 默认为0 [pageControl setNumberOfPages:kImageCount]; 2. cur ...
- 给iOS开发新手送点福利,简述UISegment的属性和用法
UISegment属性 1.segmentedControlStyle 设置segment的显示样式. typedef NS_ENUM(NSInteger, UISegmentedControlSty ...
- 给iOS开发新手送点福利,简述UIAlertView的属性和用法
UIAlertView 1.Title 获取或设置UIAlertView上的标题. 2.Message 获取或设置UIAlertView上的消息 UIAlertView *alertView = [[ ...
随机推荐
- jsx介绍
jsx与传统的html的区别: 1. jsx:使用的“元素”不局限与html中的元素,可以是任何一个React组件,传统的html是做不到的 (区分是否是组件的原则:看第一个字母是否是大写) 2.js ...
- 《TensorFlow实战》读书笔记(完结)
1 TensorFlow基础 ---1.1TensorFlow概要 TensorFlow使用数据流图进行计算,一次编写,各处运行. ---1.2 TensorFlow编程模型简介 TensorFlow ...
- pandas DataFrame 索引(iloc 与 loc 的区别)
Pandas--ix vs loc vs iloc区别 0. DataFrame DataFrame 的构造主要依赖如下三个参数: data:表格数据: index:行索引: columns:列名: ...
- Ubuntu 16.04 LTS安装 cuda8.0
参考文献: http://blog.csdn.net/autocyz/article/details/52299889 http://blog.csdn.net/lixintong1992/artic ...
- 利用WebApplicationInitializer配置SpringMVC取代web.xml
对于Spring MVC的DispatcherServlet配置方式,传统的是基于XML方式的,也就是官方说明的XML-based,如下: <servlet> <servlet-na ...
- hdu1087 dp(最大上升子序列和)
题意,给出一列数,要求所有上升子序列中序列和最大的. 这回不是求长度了,但是还是相当基础的 dp 水题,只要用 dp [ q ] 记录以 第 q 个数 a [ q ] 为结尾的上升子序列的最大的和就可 ...
- 【mysql】mac上基于tar.gz包安装mysql服务
一.准备工作 (1)下载mysql-5.7.21-macos10.13-x86_64.tar.gz,并将该压缩包移动至/usr/local目录下 (2)解压压缩包 二.安装 (1)将解压的包重命名为m ...
- vector容器的用法以及动态数组
vector容器不必去管大小 string申明的数组已经是动态的了 若是int类型的话,需要 cin>>N: int a[N]会出错 ,必须是int *p = new int[N] 然后再 ...
- 使用EntityFramework6连接MySQL
使用EntityFramework6连接MySQL 不是微软的亲儿子这待遇就是不一样,其中的坑可真实不少,第一次连MySQL足足折腾了我大半天. 废话不多说直接开始. 安装MySQL 从官网上下载最新 ...
- JAVA关闭钩子
JAVA的关闭钩子: 1. 一般应用程序在关闭时都需要做一些善后清理工作,但是用户并不会总是按照推荐的方法关闭应用程序,比如用户直接关闭控制台程序或者按下Ctrl+C结束应用程序,这样就导致清理工作得 ...