ios-UIPickerView基本使用
#import "ViewController.h" @interface ViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>
{
NSArray *pickerArray;
}
@property (weak, nonatomic) IBOutlet UIPickerView *myPickerView; @end @implementation ViewController - (void)viewDidLoad
{
[super viewDidLoad];
_myPickerView.dataSource=self;
_myPickerView.delegate=self;
_myPickerView.showsSelectionIndicator=YES;
pickerArray=[NSArray arrayWithObjects:@"",@"",@"",@"",@"",@"",@"",@"",@"",@"", nil]; } - (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return ;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return pickerArray.count;
} -(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
CGRect rect=CGRectMake(, , [self pickerView:pickerView widthForComponent:row], [self pickerView:pickerView rowHeightForComponent:row]);
UIView *testView=[[UIView alloc]initWithFrame:rect];
[testView setBackgroundColor:[UIColor clearColor]];
[testView setOpaque:YES];
UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(, , [self pickerView:pickerView widthForComponent:row]-16.0f, [self pickerView:pickerView rowHeightForComponent:row])];
[label setBackgroundColor:[UIColor clearColor]];
label.textAlignment=NSTextAlignmentCenter;
label.text=pickerArray[row];
switch (row)
{
case :
case :
{
testView.backgroundColor=component==?[UIColor greenColor]:[UIColor blueColor];
}
case :
{
testView.backgroundColor=component==?[UIColor brownColor]:[UIColor redColor];
}
break;
default:
{
testView.backgroundColor=component==?[UIColor grayColor]:[UIColor orangeColor];
}
break;
}
label.font=[UIFont boldSystemFontOfSize:14.0f];
[testView addSubview:label];
return testView;
} //可有可无
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return pickerArray[row];
}
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component;
{
return ;
}
-(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
return ;
} - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{ NSLog(@"row=%ld",row);
}
ios-UIPickerView基本使用的更多相关文章
- iOS - UIPickerView
前言 NS_CLASS_AVAILABLE_IOS(2_0) __TVOS_PROHIBITED @interface UIPickerView : UIView <NSCoding, UITa ...
- iOS UIPickerView 显示全国省市
效果图 #import "ViewController.h" @interface ViewController () @property(strong,nonatomic)UIP ...
- ios UIPickerView 技巧集锦(包括循环滚动)
摘自: http://blog.csdn.net/ipromiseu/article/details/7436521 http://www.cnblogs.com/dabaopku/archive/2 ...
- iOS:UIPickerView选择器的使用
通过UIPickerView选择器做的一个类似于密码锁的日期时间表 源码如下: #import <UIKit/UIKit.h> @interface ViewController : UI ...
- iOS学习——UIPickerView的实现年月选择器
最近项目上需要用到一个选择器,选择器中的内容只有年和月,而在iOS系统自带的日期选择器UIDatePicker中却只有四个选项如下,分别是时间(时分秒).日期(年月日).日期+时间(年月日时分)以及倒 ...
- iOS学习之自定义弹出UIPickerView或UIDatePicker(动画效果)
前面iOS学习之UIPickerView控件的简单使用 用到的UIPickerView弹出来是通过 textField.inputView = selectPicker; textField.in ...
- iOS学习之UIPickerView控件的关联选择
接上篇iOS学习之UIPickerView控件的简单使用 接着上篇的代码 http://download.csdn.net/detail/totogo2010/4391870 ,我们要实现的效果如下: ...
- iOS中UIPickerView常见属性和方法的总结
UIPickerView是iOS中的原生选择器控件,使用方便,用法简单,效果漂亮. @property(nonatomic,assign) id<UIPickerViewDataSource&g ...
- [ios]新手笔记-。-UIPickerView 关于伪造循环效果和延时滚动效果
查找了网上资料,循环效果绝大部分都是增加行数来制造循环的错觉,延时滚动就是利用NSTimer间隔出发滚动事件来制造滚动效果. 代码: #import <UIKit/UIKit.h>#imp ...
- iOS:选择器控件UIPickerView的详解和演示
选择器控件UIPickerView: 功能:它能够创建一个类似于密码锁式的单列或多列的选择菜单,用户可以通过它设置的代理来选择需要菜单中的任意的数据.例如创建日历.字体表(类型.大小.颜色).图库等. ...
随机推荐
- 二、 C#调用存储过程
个人比较喜欢使用第二种传递参数的方法 1. 调用的方法 public DataTable ExceStoredProcedure (string strCom, SqlParameter[] comm ...
- LabView中,下拉列表和枚举有什么区别?
枚举变量只能针对无符号整型数据U32,U16,U8; 而下拉列表则可以包括扩展精度,双精度,单精度,64位.长.双字节.单字节整型以及各种无符号整型(如下图黑色部分). 下拉列表
- Spring.Scheduling.Quartz的使用
最近因使用Spring.Net框架而接触.了解到其与Quartz.Net的集成,即Spring.Scheduling.Quartz模块. Spring通过对Quartz.Net的封装,采用了sprin ...
- class bool
class bool(int): """ bool(x) -> bool Returns True when the argument x is true, Fal ...
- POJ 2828Buy Tickets
POJ 2828 题目大意是说有n个插入操作,每次把B插入到位置A,原来A以后的全部往后移动1,球最后的序列 tree里保存的应该是这整个区间还有多扫个位置可以插入数据,那么线段树里从后往前扫描依次插 ...
- setsockopt的作用列表
功能描述: 获取或者设置与某个套接字关联的选 项.选项可能存在于多层协议中,它们总会出现在最上面的套接字层.当操作套接字选项时,选项位于的层和选项的名称必须给出.为了操作套接字层的选项,应该 将层的值 ...
- ASP.NET服务器控件在IE10浏览器(非兼容模式)下报脚本错误的可能解决办法
关于IE10出现LinkButton点击无效的情况: 一般高配置的系统如Win7旗舰版SP1系统不会出现这种情况,针对家庭普通版和专业版的用户通过测试都有这种情况,对于开发人员要解决不同 ...
- (剑指Offer)面试题14:调整数组顺序使奇数位于偶数前面
题目: 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于位于数组的后半部分,并保证奇数和奇数,偶数和偶数之间的相对位置不变. 如果去掉约束条件: ...
- 数据库 SQL :数据库三大泛式简谈
相信,在学习数据库知识时,大家都会碰到这个概念问题:数据三大泛式,同时,在面试过程中,可能大部分面试官也会提及这个问题. 首先,看看维基百科对于三大泛式的定义: 数据库规范化,又称数据库或资料库的正规 ...
- MySQL 多会话之间更新数据的小实例
1:创建一个实验表 mysql> use test; mysql> CREATE TABLE t -> (id int(11) NOT NULL DEFAULT 0, -> n ...