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的属性和用法的更多相关文章

  1. 给iOS开发新手送点福利,简述UIImagePickerController的属性和用法

    1.+(BOOL)isSourceTypeAvailable:(UIImagePickerControllerSourceType)sourceType;         // 检查指定源是否在设备上 ...

  2. 给iOS开发新手送点福利,简述UITableView的属性和用法

    UITableView UITableView内置了两种样式:UITableViewStylePlain,UITableViewStyleGrouped   <UITableViewDataSo ...

  3. 给iOS开发新手送点福利,简述UIView的属性和用法

    UIView 1.alpha 设置视图的透明度.默认为1. // 完全透明 view.alpha = 0; // 不透明 view.alpha = 1; 2.clipsToBounds // 默认是N ...

  4. 给iOS开发新手送点福利,简述UITextField的属性和用法

    UITextField属性 0.     enablesReturnKeyAutomatically 默认为No,如果设置为Yes,文本框中没有输入任何字符的话,右下角的返回按钮是disabled的. ...

  5. 给iOS开发新手送点福利,简述UILabel的属性和用法

    UILabel属性 1.text:设置标签显示文本. label.text = @"我是Label"; 2.attributedText:设置标签属性文本. NSString *t ...

  6. 给iOS开发新手送点福利,简述UIScrollView的属性和用法

    UIScrollView 1.   contentOffset 默认CGPointZero,用来设置scrollView的滚动偏移量. // 设置scrollView的滚动偏移量 scrollView ...

  7. 给iOS开发新手送点福利,简述UIPageControl的属性和用法

    UIPageControl 1.   numberOfPages // 设置有多少页 默认为0 [pageControl setNumberOfPages:kImageCount]; 2.   cur ...

  8. 给iOS开发新手送点福利,简述UISegment的属性和用法

    UISegment属性 1.segmentedControlStyle 设置segment的显示样式. typedef NS_ENUM(NSInteger, UISegmentedControlSty ...

  9. 给iOS开发新手送点福利,简述UIAlertView的属性和用法

    UIAlertView 1.Title 获取或设置UIAlertView上的标题. 2.Message 获取或设置UIAlertView上的消息 UIAlertView *alertView = [[ ...

随机推荐

  1. flash存储原理

    norflash 带有 SRAM接口,有足够的地址引脚来寻址,可以很容易地存取其内容每一字节:nandflash器件使用复杂的IO口串行的存取数据,读写操作采用512字节的块(也就是读/写某个字节,必 ...

  2. Executors Future Callable 使用场景实例

    https://www.jb51.net/article/132606.htm: 我们都知道实现多线程有2种方式,一种是继承Thread,一种是实现Runnable,但这2种方式都有一个缺陷,在任务完 ...

  3. com.fasterxml.jackson.databind.ObjectMapper. .readValue .convertValue

    String str="{\"student\":[{\"name\":\"leilei\",\"age\": ...

  4. WPF中使用BitmapImage处理图片文件(转)

    (1)图片从文件导入 BitmapImage image = new BitmapImage(); image.BeginInit(); image.UriSource = new Uri(filen ...

  5. 红黑树-算法大神的博客-以及java多线程酷炫的知识

    http://www.cnblogs.com/skywang12345/p/3245399.html 解释第5条:从 ->根节点(或者任意个结点)到->所有的末端节点的路径中 ->黑 ...

  6. aircrack-ng 工具集学习

    一.aircrack-ng简介 aircrack-ng是Aircrack项目的一个分支.是一个与802.11标准的无线网络分析有关的安全软件,主要功能有:网络侦测,数据包嗅探,WEP和WPA/WPA2 ...

  7. Android 第三方分享中遇到的问题以及解决方式

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/liuxian13183/article/details/36189343               ...

  8. cocos2dx学习资料

    [9秒原创]cocos2d-x——CCScrollView用法 http://www.9miao.com/thread-45619-1-1.html [9秒原创]cocos2d-x——场景切换效果示例 ...

  9. Openssl将crt证书和key私钥合成pfx证书

    下载OpenSSL地址:http://slproweb.com/products/Win32OpenSSL.html 下载安装openssl 选择对应OpenSSL版本进行下载下载. 运行安装程序Wi ...

  10. 使用 Visual Studio Code (VSCODE)写 C51 (持续更新 2018-04-09)

    Keil C51 那代码编辑器就是上一个时代的产物, 不适合现代人使用. 但是用 Visual Studio Code (VSCODE)就舒服多了.但需要安装和配置一些扩展: 按 Ctrl + Shi ...