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: 功能:它能够创建一个类似于密码锁式的单列或多列的选择菜单,用户可以通过它设置的代理来选择需要菜单中的任意的数据.例如创建日历.字体表(类型.大小.颜色).图库等. ...
随机推荐
- oracle 去掉空格
trim(value) 去掉左右空格 ltrim(value) 去掉左空格 rtrim(value) 去掉右空格
- labview视频采集IMAdx
grab(连续采集) 摄像头打开之后便一直采集图像,存储在IMAQ开辟的临时空间里,只要while循环不断的读取临时空间就可以显示当前图像(grab调用的是image句柄)
- hdu 2444 The Accomodation of Students(最大匹配 + 二分图判断)
http://acm.hdu.edu.cn/showproblem.php?pid=2444 The Accomodation of Students Time Limit:1000MS Me ...
- flask中的session对象方法
'clear', 'copy', 'fromkeys', 'get', 'has_key', 'items', 'iteritems', 'iterkeys', 'itervalues', 'keys ...
- iOS开发中的测试框架
转载作者:@crespoxiao 我们为什么要用测试框架呢?当然对项目开发有帮助了,但是业内现状是经常赶进度,所以TDD还是算了吧,BDD就测测数据存取和重要环节,这很重要,一次性跑完测试单元检查接口 ...
- 1) data-options
<select class="easyui-combobox" data-options="editable:false"> <select ...
- [Linux]常用命令与目录全拼
命令缩写: ls:list(列出目录内容)cd:Change Directory(改变目录)su:switch user 切换用户rpm:redhat package manager 红帽子打包管理器 ...
- Ubuntu 搭建PHP开发环境
Ubuntu确实很好玩.有喜欢的命令行,简洁的界面,不同于Window要的感觉.偶尔换换环境工作,学习Linux的思维方式,是一种不错的做 法.之前也折腾过Ubuntu,不过,因为网络的问题,一直没有 ...
- 无责任Windows Azure SDK .NET开发入门篇二[使用Azure AD 进行身份验证]
二.使用Azure AD进行身份验证 之所以将Azure AD 作为开始,是应为基本上我们所有应用都需要进行安全管理.Azure Active Directory (Azure AD) 通过以下方式简 ...
- Hadoop on Mac with IntelliJ IDEA - 5 解决java heap space问题
本文讲述在CentOS 6.5中提交作业到hadoop 1.2.1于reduce阶段遇到Error: java heap space错误导致作业重新计算的解决过程.解决办法适用Linux.Mac OS ...