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. 添加react-router

    1.index.js 内容: import React from 'react' import ReactDOM from 'react-dom' import { renderRoutes } fr ...

  2. Centos编译Unix网络编程(第三版)卷1的源代码

    测试环境:Centos 1)在shell中输入./configure然后按回车(注意先让configure有执行权限 chomd 777 configure) 2)依次进入lib.libfree.li ...

  3. 【论文解读】行人检测:What Can Help Pedestrian Detection?(CVPR'17)

    前言 本篇文章出自CVPR2017,四名作者为Tsinghua University,Peking University, 外加两名来自Megvii(旷视科技)的大佬. 文章中对能够帮助行人检测的ex ...

  4. 【error】no type named ‘type’ in ‘class std::result_of<void

    Q: std::thread fs_module(fs_process, prob_orig, fb_sz, line_num, probp, plabel, std::ref(confidence_ ...

  5. BZOJ4475: [Jsoi2015]子集选取【找规律】【数学】

    Description Input 输入包含一行两个整数N和K,1<=N,K<=10^9 Output 一行一个整数,表示不同方案数目模1,000,000,007的值. Sample In ...

  6. 我的第一个Mybatis程序

    第一个Mybatis程序 在JDBC小结中(可以参阅本人JDBC系列文章),介绍到了ORM,其中Mybatis就是一个不错的ORM框架 MyBatis由iBatis演化而来 iBATIS一词来源于“i ...

  7. POJ2182 Lost Cows

    题意 Language:Default Lost Cows Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13448 Accep ...

  8. BZOJ4713 迷失的字符串

    分析 首先考虑只有一个串时的做法,可以进行背包dp,记\(f(i,j)\)表示从\(i\)的子树中某点出发到\(i\)能否匹配字符串的\(1 \dots j\)位且\(i\)与\(j\)匹配.同时记\ ...

  9. 移动端 元素外面使用伪类after加边框 导致其内部元素无法选中

    解决方法:给内部元素增加属性 position: relative; z-index: 3; 这样就能选中其内部元素了.

  10. sql server insert values 多值 与oracle 的不同

    类似的语句在 oracle 中是不能执行的 insert into temp_tbl values('app'),('demo'); 但是在sql server 中是可以的 insert into c ...