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 ...
随机推荐
- valgrind 内存检测与调用图生成
http://blog.csdn.net/destina/article/details/6198443 感谢作者的分享! 一 valgrind是什么? Valgrind是一套Linux下,开放源 ...
- Sharepoint 列表ItemAdding事件判断文件类型、获取当前上传的文件
using System; using System.Security.Permissions; using Microsoft.SharePoint; using Microsoft.SharePo ...
- spark1.2.0编译
spark 有三种编译方式:SBT.MAVEN.make-distribution.sh.SBT.MAVEN两种方式打出来的包比较大,不适合部署使用.因此我们通常使用第三种方式打包. ./make-d ...
- Dispatcher中Invoke与BeginInvoke
[同步]Invoke Application.Current.Dispatcher.Invoke(AutoIncreaseNumber); [异步]BeginInvoke Application.Cu ...
- IOS NS 字符串 数组 字典 文件 动态 静态 操作
ios 常用字符串的操作 //将NSData转化为NSString NSString* str = [[NSString alloc] initWithData:response e ...
- 2.1.4 扫描器X-Scan查本机隐患
X-Scan是由安全焦点开发的一个功能强大的扫描工具.它采用多线程方式对指定IP地址段(或单机)进行安全漏洞检测,支持插件功能. 1.用X-Scan查看本机IP地址 利用X-Scan扫描器来查看本机的 ...
- MVC框架 - AJAX支持
Ajax是异步JavaScript和XML的一个简写形式.MVC框架包含了不显眼的Ajax内置支持,通过它可以使用辅助方法,在所有的视图添加代码来定义Ajax特性. 在MVC中此特征是基于jQuery ...
- Java基础知识强化之IO流笔记78:NIO之 FileChannel
Java NIO中的FileChannel是一个连接到文件的通道.可以通过文件通道读写文件. FileChannel无法设置为非阻塞模式,它总是运行在阻塞模式下. 1. 打开FileChannel 在 ...
- ReentrantLock类的基本结构
ReentrantLock类是一个可重入互斥锁,它具有与使用synchronized()方法和语句访问隐式监视器锁相同的基本行为和语义,但是它的功能更强大.ReentrantLock由最近成功获得锁但 ...
- Session共享的简单总结
1.同服务器.同一域名.不同应用(端口.虚拟目录等) 这种很简单,把sessionState保存到SQLServer,aspnet_regsql之后,修改存储过程TempGetAppID,把 SET ...