UIPickerView选择器的使用方法
UIPickerView是选择列表内容的控件 使用方法与UITableView类似
都需要用array传入数据 用Delegate DataSource中的代理方法实现各种显示功能
@interface MainViewController ()<UIPickerViewDelegate,UIPickerViewDataSource>
{
NSMutableArray* hourArray;//显示小时的数组
NSMutableArray* minuteArray;//显示分钟的数组
}
@end @implementation MainViewController - (void)viewDidLoad {
//时间选择器
UIPickerView* datePicker=[UIPickerView new];
datePicker.frame=CGRectMake(, , SCREEN_WIDTH-, );
datePicker.backgroundColor=[UIColor whiteColor];
datePicker.delegate=self;
datePicker.dataSource=self;
datePicker.backgroundColor=COLOR_PINK;
[self.view addSubview:datePicker]; hourArray=[[NSMutableArray alloc]initWithCapacity:];
for (int i=; i<=; i++) {
[hourArray addObject:[NSString stringWithFormat:@"%@%d",(i<) ? @"":@"", i]];
} minuteArray=[[NSMutableArray alloc]initWithCapacity:];
for (int i=; i<=; i++) {
[minuteArray addObject:[NSString stringWithFormat:@"%@%d",(i<) ? @"":@"", i]];
}
} #pragma mark ********** UIPickerViewDataSource ********** #pragma mark 返回UIPickerView的分组数
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{
return ;
} #pragma mark 返回UIPickerView的每组行数 component为每组的索引
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
{
if (component==) {
return ;
}
return ;
} #pragma mark 返回UIPickerView的每个单元显示的数据
- (nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
{
if (component==) {
return [hourArray objectAtIndex:row];
}
return [minuteArray objectAtIndex:row];
} #pragma mark 更改UIPickerView的文字样式 通过修改label实现
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(nullable UIView *)view;
{
UILabel* pickerLabel = (UILabel*)view;
if (!pickerLabel){
pickerLabel = [[UILabel alloc] init];
pickerLabel.font=[UIFont systemFontOfSize: weight:];
pickerLabel.textColor=[UIColor whiteColor];
pickerLabel.textAlignment=;
[pickerLabel setBackgroundColor:[UIColor clearColor]];
}
pickerLabel.text=[self pickerView:pickerView titleForRow:row forComponent:component];
return pickerLabel;
} #pragma mark 返回UIPickerView的高度
- (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component;
{
return .f;
}
参考文献http://bbs.9ria.com/thread-279743-1-1.html
UIPickerView选择器的使用方法的更多相关文章
- UIPickerView(选择器)
UIPickerView也是一个选择器控件,它比UIDatePicker更加通用,它可以生成单列的选择器,也可生成多列的选择器,而且开发者完全可以自定义选择项的外观,因此用法非常灵活. UIPicke ...
- iOS:UIPickerView选择器的使用
通过UIPickerView选择器做的一个类似于密码锁的日期时间表 源码如下: #import <UIKit/UIKit.h> @interface ViewController : UI ...
- IOS--UIDatePicker 时间选择器 的使用方法详细
IOS--UIDatePicker 时间选择器 的使用方法详细 // 主要有下面四种类型: // 日期显示. // 日期和时间显示. // 时间显示. // 倒计时选择 // UIDa ...
- iOS中UIPickerView常见属性和方法的总结
UIPickerView是iOS中的原生选择器控件,使用方便,用法简单,效果漂亮. @property(nonatomic,assign) id<UIPickerViewDataSource&g ...
- jQuery选择器和选取方法 http://www.cnblogs.com/MaxIE/p/4078869.html
我们已经使用了带有简单Css选择器的jQuery选取函数:$().现在是时候深入了解jQuery选择器语法,以及一些提取和扩充选中元素集的方法了. 一.jQuery选择器 在CSS3选择器标淮草案定义 ...
- JavaScript学习笔记-选择器集合调用方法
<script type="text/javascript"> function uu(namePd) { //判断id var reId = new RegExp(/ ...
- jQuery选择器和选取方法
我们已经使用了带有简单Css选择器的jQuery选取函数:$().现在是时候深入了解jQuery选择器语法,以及一些提取和扩充选中元素集的方法了. 一.jQuery选择器 在CSS3选择器标淮 ...
- jQuery 学习笔记(3)(内容选择器、attr方法、prop方法,类的操作)
内容选择器: 1.$("div:empty"): 空的div元素 2.$("div:parent"): 非空div元素 3.$("div:contai ...
- jQuery选择器和选取方法.RP
我们已经使用了带有简单Css选择器的jQuery选取函数:$().现在是时候深入了解jQuery选择器语法,以及一些提取和扩充选中元素集的方法了. 一.jQuery选择器 在CSS3选择器标淮草案定义 ...
随机推荐
- 2016-2017-2《程序设计与数据结构》学生博客&git@OSC
2016-2017-2<程序设计与数据结构>学生博客&git@OSC 博客园 20162301张师瑜 20162302杨京典 20162303石亚鑫 20162304张浩林 201 ...
- 使用TaskManager爬取2万条代理IP实现自动投票功能
话说某天心血来潮想到一个问题,朋友圈里面经常有人发投票链接,让帮忙给XX投票,以前呢会很自觉打开链接帮忙投一票.可是这种事做多了就会考虑能不能使用工具来进行投票呢,身为一名程序猿决定研究解决这个问题. ...
- VMware虚拟网络编辑器
摘要:很多已经使用VMware很久的同学,也没有接触过VMware的虚拟网络编辑器这个工具.其 实这个工具非常有用.功能也很强大. 我们都知道,安装了VMware软件后,系统中会自动出现VMnet ...
- inline-block元素间距
做项目过程中发现元素设置为inline-block后,彼此之间会有间距,有时候不是我们想要的效果,这时候就需要将间距去除掉. 后来上网查了下,已有前人总结了不少好的方法.这里主要借鉴了张鑫旭博客中介绍 ...
- getline数据来源你的三种方式
(1)getline从交互式的用户输入中\c中获取内容: # awk 'BEGIN {system("echo \"Input your name:\"");g ...
- php 不用四舍五入的方式截取小数点后两位
/** * 字符串截取, 默认小数点后2位 * @param $money * @param int $accuracy * @return float */ private function fil ...
- C语言拾遗(一)
越来越体会到C语言的重要性,不管是在计算机底层的理解上,还是在算法数据结构上,所以遂决定重新拾起C语言,不定期更新一些知识点. 推荐博客:http://blog.csdn.net/itcastcpp ...
- 关于获取、设置css样式封装的函数入门版
<html> <head> <meta charset="UTF-8"> <title>CSS样式的获取和设置:简单版</ti ...
- Google开源库-Volley的使用
一.什么是Volley? Volley is an HTTP library that makes networking for Android apps easier and most import ...
- 如何实现CDN的ns智能解析和动手验证Akamai的实现
1.什么是ns智能解析 通常CDN业务中,智能解析域名,是根据请求方ip的不同给出不同的A记录. 而ns智能解析,是根据请求方ip的不同让他去不同的ns上解析域名,把ns推向离用户更近的边缘节点来缩短 ...