#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);
}

最新文章

  1. C# BlockCollection
  2. Win10无法安装提示磁盘布局不受UEFI固件支持怎样解决
  3. Uber优步宁波司机注册正式开始啦! UBER宁波司机注册指南!
  4. 一次领域驱动设计(DDD)的实际应用
  5. iOS 设计模式之工厂模式
  6. UVa401 回文词
  7. 使用Yeoman搭建 AngularJS 应用 (3) —— 让我们搭建一个网页应用
  8. Http请求头中的字段理解
  9. font awesome使用笔记
  10. vijos 1942 [AH 2005] 小岛
  11. Webpack 4教程 - 第六部分 增强开发时体验
  12. cocos图片的选择以及压缩
  13. 更改Oracle字符集避免乱码
  14. fk输入地壳模型容易出错的地方
  15. strcmp用法
  16. tomcat下安装jenkins
  17. 1415. [NOIP2001]数的计数
  18. npm 安装 不快的解决办法
  19. 20145314郑凯杰 《Java程序设计》课程总结
  20. Redis 的安装配置介绍

热门文章

  1. 解决getOutputStream() has already been called for this response
  2. gdb之watch命令
  3. Java反射机制(Class类的使用)
  4. oracle学习 七 拼接变量+日期函数(持续更)
  5. ASP.NET的分页方法(四)
  6. HDU 1561The more, The Better(树形DP)
  7. POJ3974 Palindrome (manacher算法)
  8. 联想硬盘分区表格式修改 GPT -&gt; MBR
  9. JavaScript要点(十七) Math 对象
  10. js 基于函数伪造的方式实现继承