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: 功能:它能够创建一个类似于密码锁式的单列或多列的选择菜单,用户可以通过它设置的代理来选择需要菜单中的任意的数据.例如创建日历.字体表(类型.大小.颜色).图库等. ...
随机推荐
- MYSQL数据库性能调优之七:其他(读写分离、分表等)
一.分表 水平划分 垂直划分 二.读写分离 三.选择合理的数据类型 特别是主键 四.文件.图片等大文件使用文件系统存储 五.数据库参数配置 注意:max_connections最大连接数一般设置在10 ...
- global & nonlocal
name = "A" def test(): name = "B" def test2(): global name # global 指的是拿到的是全局的变量 ...
- 删除qq历史签名
我们在设置新的个性签名的时候之前的签名会被记录,我们可以用手机qq删除这些历史签名,告别过去,做崭新的自己. 到需要删除的历史签名, 从右至左滑动屏幕
- iOS KVC/KVO/KVB
看了那么多博客.描述那么复杂,其实KVC很简单,没描述的那么复杂,所以写一篇简单的易于理解的博文,切入正文: 1.KVC底层是通过runtime对method和value操作 比如说如下的一行KVC ...
- CSS单词换行and断词
背景 某天老板在群里反馈,英文单词为什么被截断了? 很显然,这是我们前端的锅,自行背锅.这个问题太简单了,css里加两行属性,分分钟搞定. 1 2 word–break: keep–all; wo ...
- CodeForces 709C Letters Cyclic Shift (水题)
题意:给定一个字符串,让你把它的一个子串字符都减1,使得总字符串字典序最小. 析:由于这个题是必须要有一个字串,所以你就要注意这个只有一个字符a的情况,其他的就从开始减 1,如果碰到a了就不减了,如果 ...
- CentOS 安装 gcc
centos linux默认可以采用yum方式安装,则采用如下命令安装gcc编译器即可:#yum -y install gcc 系统会自动安装gcc及依赖组件 gcc ...
- Spring REST实践之客户端和测试
RestTemplate 可参考spring实战来写这部分. RestTemplate免于编写乏味的样板代码,RestTemplate定义了33个与REST资源交互的方法,涵盖了HTTP动作的各种形式 ...
- DIV 布局 左中右
<style type="text/css">body{ margin:0; padding:0;}.Header{ height:100px; background: ...
- mvc4帮助类
@App @AppState @Ajax @Cache @Context @Culture @Html @IsPost @Layout @Model @Output @OutputStack @Pag ...