UIPickerView基本用法
#import "ViewController.h"
#import <UIKit/UIKit.h>
@interface ViewController : UIViewController<UIPickerViewDelegate,UIPickerViewDataSource>
{
UILabel *lable;
NSArray *array;
}
@end
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
array=[NSArray arrayWithObjects:@"0",@"1",@"2",@"3" ,@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",nil];
UIButton *button3=[UIButton buttonWithType:UIButtonTypeCustom];
button3.backgroundColor=[UIColor greenColor];
button3.frame=CGRectMake(100, 300, 120, 50);
[button3 addTarget:self action:@selector(showMyPickerView:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button3];
}
-(void)showMyPickerView:(UIButton *)sender
{
//UIPickerView选择器的功能
UIView *whiteView=[[UIView alloc]initWithFrame:self.view.frame];
//添加视图进行遮挡
whiteView.tag=150;
whiteView.backgroundColor=[UIColor whiteColor];
[self.view addSubview:whiteView];
//UIPickerView选择器的功能,实现数据的选择
UIPickerView *pickerView1=[[UIPickerView alloc]initWithFrame:CGRectMake(0, 0, 280, 300)];
pickerView1.center=whiteView.center;
pickerView1.delegate=self;
pickerView1.dataSource=self;
[whiteView addSubview:pickerView1];
UIButton *button0=[UIButton buttonWithType:UIButtonTypeCustom];
button0.frame=CGRectMake(0, 0, 80, 60);
button0.backgroundColor=[UIColor greenColor];
[button0 setTitle:@"close" forState:UIControlStateNormal];
[button0 addTarget:self action:@selector(closePickerView:) forControlEvents:UIControlEventTouchUpInside];
[whiteView addSubview:button0];
lable=[[UILabel alloc]initWithFrame:CGRectMake(100,20, 200, 40)];
lable.backgroundColor=[UIColor yellowColor];
lable.tag=160;
[whiteView addSubview:lable];
}
-(void)closePickerView:(UIButton *)sender
{
UIView *removeView=[self.view viewWithTag:150];
[removeView removeFromSuperview];//移除白色遮挡视图
}
//返回选择器的列数
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 2;
}
//返回当前显示的行数
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return array.count;
}
//显示数组中的数字在对应的行中
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
return [array objectAtIndex:row];
}
//获取单元行的内容
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
NSString *str1=[array objectAtIndex:row];
NSString *string1=[self pickerView:pickerView titleForRow:row forComponent:0];
UILabel *getlable=(UILabel *)[self.view viewWithTag:160];
NSLog(@"%@---%@",str1,string1);
getlable.text=string1;
}
UIPickerView基本用法的更多相关文章
- iOS学习——UIPickerView的实现年月选择器
最近项目上需要用到一个选择器,选择器中的内容只有年和月,而在iOS系统自带的日期选择器UIDatePicker中却只有四个选项如下,分别是时间(时分秒).日期(年月日).日期+时间(年月日时分)以及倒 ...
- UIPickerView用法(左右比例,整体大小,字体大小)
UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectZero]; pickerView.autoresizingM ...
- Swift - 选择框(UIPickerView)的用法
1,选择框可以让用户以滑动的方式选择值.示例如下: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 ...
- UIPickerView的使用(一)
简介:UIPickerView是一个选择器控件,它比UIDatePicker更加通用,它可以生成单列的选择器,也可生成多列的选择器,而且开发者完全可以自定义选择项的外观,因此用法非常灵活.UIPick ...
- iOs基础篇(二十二)—— UIPickerView、UIDatePicker控件的使用
一.UIPickerView UIPickerView是一个选择器控件,可以生成单列的选择器,也可生成多列的选择器,而且开发者完全可以自定义选择项的外观,因此用法非常灵活. 1.常用属性 (1)num ...
- ios开发 <AppName>-Prefix.pch文件的用法详解
我们知道,每新建立一个工程,比如说HelloWord,在分类SupportingFiles里都会有一个以工程名开头-Prefix.pch结尾的文件,如HelloWord-Prefix.pch.对于这个 ...
- iOS开发——高级UI之OC篇&UIdatePicker&UIPickerView简单使用
UIdatePicker&UIPickerView简单使用 /***************************************************************** ...
- UIPickerView
1.UIPickView什么时候用? 通常在注册模块,当用户需要选择一些东西的时候,比如说城市,往往弹出一个PickerView给他们选择. UIPickView常见用法,演示实例程序 1> 独 ...
- UIPickerView(选择器)
UIPickerView也是一个选择器控件,它比UIDatePicker更加通用,它可以生成单列的选择器,也可生成多列的选择器,而且开发者完全可以自定义选择项的外观,因此用法非常灵活. UIPicke ...
随机推荐
- ext2元数据结构
概述 本篇博客主要描述ext2文件系统中的各种典型元数据结构,其中包括文件系统级别的元数据,如超级块,块组描述符等,也包括文件级的元数据,如文件目录项,文件inode等. ex ...
- global $GLOBALS区别
<?phpfunction &test(){ static $b=0;//申明一个静态变量 $b=$b+1; echo $b; return $b; }} ...
- oracle中to_date() 与 to_char() 日期和字符串转换
to_date("要转换的字符串","转换的格式") 两个参数的格式必须匹配,否则会报错. 即按照第二个参数的格式解释第一个参数. to_char(日期,& ...
- Spring3中js/css/jpg/gif等静态资源无法找到(No mapping found for HTTP request with URI)问题解决--转载
原文地址:http://www.programgo.com/article/96083031845/ 最近项目中使用到Spring3,在感叹Spring3注解配置清爽的同时竟然出现了这个不和谐的事情, ...
- linux修改history
1.cat ~/.bash_history cat -n ~/.bash_history [以行数的形式查看] 2.history | more Enter 键盘 ----------一行一行 空 ...
- Java再学习——CopyOnWrite容器
一,定义 CopyOnWrite容器即写时复制的容器.通俗的理解是当我们往一个容器添加元素的时候,不直接往当前容器添加,而是先将当前容器进行Copy,复制出一个新的容器,然后新的容器里添加元素,添加完 ...
- 1.4.7 Schema API
Schema API Schema API允许使用REST API每个集合(collection)(或者单机solr的核(core)).包含了定义字段类型,字段,动态字段,复制字段等.在solr4.2 ...
- Oracle基础<5>--触发器
一.触发器 触发器是当特定事件出现时自动执行的代码块.比如,每次对员工表进行增删改的操作时,向日志表中添加一条记录.触发器和存储过程是由区别的:触发器是根据某些条件自动执行的,存储过程是手动条用的. ...
- Umbraco(4)-Outputting the Document Type Properties(翻译文档)
翻译原文地址:http://www.ncloud.hk/%E6%8A%80%E6%9C%AF%E5%88%86%E4%BA%AB/umbraco4outputting-the-document-typ ...
- first集合及follow集合
前面那片文章生成的语法分析表并不是最优的,因为有些项在遇到错误输入的时候,并不是采取报错,而是执行规约,直到不能再规约的时候才报错.这是不科学的,我们需要在得到错误输入的时候立马报错,为了实现这个功能 ...