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. SVM实现分类识别及参数调优(一)

    前言 项目有一个模块需要将不同类别的图片进行分类,共有三个类别,使用SVM实现分类. 实现步骤: 1.创建训练样本库: 2.训练.测试SVM模型: 3.SVM的数据要求: 实现系统: windows_ ...

  2. AOP jdk动态代理

    一: jdk动态代理是Spring AOP默认的代理方法.要求 被代理类要实现接口,只有接口里的方法才能被代理,主要步骤是先创建接口,接口里创建要被代理的方法,然后定义一个实现类实现该接口,接着将被代 ...

  3. HDU 2546:饭卡(01背包)

    饭卡 Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submiss ...

  4. Tempter of the Bone dfs+剪枝

    The doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it u ...

  5. 有锁Iphone 3GS 6.0.1 降级刷到4.2.1 完美越狱+解锁

    2012-12-20 百度空间所写 前言:由于之前的3GS升级到6.0.1后会有重启之后无法打电话的情况,同学觉得这样很烦,搞得手机不像个手机了.但是这也是没办法的,毕竟是不完美越狱加软解锁的.于是, ...

  6. 《DSP using MATLAB》Problem 4.17

  7. JavaScript原型继承工作原理

    原型继承的定义 当你阅读关于JS原型继承的解释时,你时常会看到以下这段文字: 当查找一个对象的属性时,JavaScript 会向上遍历原型链,直到找到给定名称的属性为止.——出自JavaScript秘 ...

  8. 使用MVC5的Entity Framework 6入门 ---- 系列教程

    使用MVC5的Entity Framework 6入门(十二)——为ASP.NET MVC应用程序使用高级功能 为ASP.NET MVC应用程序使用高级功能这是微软官方教程Getting Starte ...

  9. Apache2.4配置(全)

    http://blog.csdn.net/u012291157/article/details/46492137

  10. python类的继承的两种方式

    class Animal(object): """docstring for Animal""" def __init__(self, na ...