#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基本用法的更多相关文章

  1. iOS学习——UIPickerView的实现年月选择器

    最近项目上需要用到一个选择器,选择器中的内容只有年和月,而在iOS系统自带的日期选择器UIDatePicker中却只有四个选项如下,分别是时间(时分秒).日期(年月日).日期+时间(年月日时分)以及倒 ...

  2. UIPickerView用法(左右比例,整体大小,字体大小)

    UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:CGRectZero]; pickerView.autoresizingM ...

  3. 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 ...

  4. UIPickerView的使用(一)

    简介:UIPickerView是一个选择器控件,它比UIDatePicker更加通用,它可以生成单列的选择器,也可生成多列的选择器,而且开发者完全可以自定义选择项的外观,因此用法非常灵活.UIPick ...

  5. iOs基础篇(二十二)—— UIPickerView、UIDatePicker控件的使用

    一.UIPickerView UIPickerView是一个选择器控件,可以生成单列的选择器,也可生成多列的选择器,而且开发者完全可以自定义选择项的外观,因此用法非常灵活. 1.常用属性 (1)num ...

  6. ios开发 <AppName>-Prefix.pch文件的用法详解

    我们知道,每新建立一个工程,比如说HelloWord,在分类SupportingFiles里都会有一个以工程名开头-Prefix.pch结尾的文件,如HelloWord-Prefix.pch.对于这个 ...

  7. iOS开发——高级UI之OC篇&UIdatePicker&UIPickerView简单使用

    UIdatePicker&UIPickerView简单使用 /***************************************************************** ...

  8. UIPickerView

    1.UIPickView什么时候用? 通常在注册模块,当用户需要选择一些东西的时候,比如说城市,往往弹出一个PickerView给他们选择. UIPickView常见用法,演示实例程序 1> 独 ...

  9. UIPickerView(选择器)

    UIPickerView也是一个选择器控件,它比UIDatePicker更加通用,它可以生成单列的选择器,也可生成多列的选择器,而且开发者完全可以自定义选择项的外观,因此用法非常灵活. UIPicke ...

随机推荐

  1. XCode4中的文本查找和文本替换功能

    转自:http://blog.csdn.net/zhuzhihai1988/article/details/7843186 1.如果是在打开的文档范围内:       查找: Command+ F   ...

  2. 《嵌入式Linux基础教程学习笔记一》

    常用书目下载地址:http://www.cnblogs.com/pengdonglin137/p/3688029.html 第二章 1.进程上下文和中断上下文(Page20) 当应用程序执行系统调用, ...

  3. iOS H5 容器的一些探究(一):UIWebView 和 WKWebView 的比较和选择

    来源:景铭巴巴 链接:http://www.jianshu.com/p/84a6b1ac974a 一.Native开发中为什么需要H5容器 Native开发原生应用是手机操作系统厂商(目前主要是苹果的 ...

  4. 利用<JavascriptSerializer类> 进行Json对象的序列化和反序列化

    1. 首先, JavascriptSerializer类所在名空间: using System.Web.Script.Serialization; 2. 相关的3篇文章, 标记下: 使用JavaScr ...

  5. c#删除转义字符的方法,删除\0后所有字符串(菜鸟级别)

    string str = "78738\01212"; string str_2= Regex.Unescape(str); int index = str_2.IndexOf(& ...

  6. PostgreSQL异步客户端(并模拟redis 数据结构)

    以前为了不在游戏逻辑(对象属性)变更时修改数据库,就弄了个varchar字段来表示json,由服务器逻辑(读取到内存)去操作它. 但这对运维相当不友好,也不能做一些此Json数据里查询. 所以后面就用 ...

  7. 在Archlinux ARM - Raspberry Pi上安装Google coder

    升级软件包 一个 pacman 命令就可以升级整个系统.花费的时间取决于系统有多老.这个命令会同步非本地(local)软件仓库并升级系统的软件包: # pacman -Syu 提示:确保make以及g ...

  8. java如何判断字符串是否为空的方法

    以下是java 判断字符串是否为空的四种方法: 方法一: 最多人使用的一个方法, 直观, 方便, 但效率很低: if(s == null ||"".equals(s)); 方法二: ...

  9. 安装 ant

    (1)下载ant:http://ant.apache.org/bindownload.cgi (2)解压后放在指定的文件夹中(/usr/lib) (3) sudo chmod 777 /usr/lib ...

  10. maven 添加中央仓库中没有的jar

    jar文件需要放到当前目录下,执行以下命令,设置 groupId,artifactId,version信息,方便项目pom引用 mvn install:install-file -Dfile=xxx. ...