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 ...
随机推荐
- IOPS
http://www.cnblogs.com/sink_cup/archive/2012/09/14/ssd_iops_sql_nosql.html http://www.techrepublic.c ...
- 主流手持设备GPU性能比较
设备 GPU CPU 每秒像素填充率 每秒三角形生成 内存 iPhone4 PowerVR SGX 535 ARM Cortex-A8 800M 512M iPod touch 4 Power ...
- 高级I/O之I/O多路转接——pool、select
当从一个描述符读,然后又写到另一个描述符时,可以在下列形式的循环中使用阻塞I/O: ) if (write(STDOUT_FILENO, buf, n) != n) err_sys("wri ...
- 认清Linux中标准输入和标准输出的双重含义
按照惯例,UNIX系统shell使用文件描述符0与进程的标准输入(一般是键盘)相关联,文件描述符1与标准输出(一般是显示器)相关联,文件描述符2与标准出错输出(一般是显示器)相关联. 在依从POSIX ...
- 如何写出好的Java代码?
1. 优雅需要付出代价.从短期利益来看,对某个问题提出优雅的解决方法,似乎可能花你更多的时间.但当它终于能够正确执行并可轻易套用于新案例中,不需要花上数以时计,甚至以天计或以月计的辛苦代价时,你会看得 ...
- nodejs的mysql模块学习(五)数据库连接配置之SSL
SSL选项 在SSL连接选项中需要一个字符串 或者对象 当是字符串的时候 将使用预定义的SSL配置文件 "Amazon RDS" 只有这一个预定义配置文件 用来连接到亚马逊RDS服 ...
- css文字截取
给文字设置宽度 text-overflow:ellipsis; //超出部分用...表示 white-space:nowrap; //禁止换行 overflow:hidden; //超出部分的文字隐 ...
- C# 递归程序 获取某个节点下的全部子节点
/// <summary> /// 获取组织结构树 /// </summary> /// <param name="list"></par ...
- 重构3-Pull Up Method(方法上移)
上移方法(Pull Up Method)重构是将方法向继承链上层迁移的过程.用于一个方法被多个实现者使用时 public abstract class Vehicle { // other metho ...
- 关于JPA方法名创建自动查询
JPA 的根据解析方法名称自动对接口进行实现的方法能节省大量的资源,以下对于解析规则进行列举哈 商品实体类 package com.dionren.zhaoxie.entity.trade; impo ...