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选择器的使用方法的更多相关文章

  1. UIPickerView(选择器)

    UIPickerView也是一个选择器控件,它比UIDatePicker更加通用,它可以生成单列的选择器,也可生成多列的选择器,而且开发者完全可以自定义选择项的外观,因此用法非常灵活. UIPicke ...

  2. iOS:UIPickerView选择器的使用

    通过UIPickerView选择器做的一个类似于密码锁的日期时间表 源码如下: #import <UIKit/UIKit.h> @interface ViewController : UI ...

  3. IOS--UIDatePicker 时间选择器 的使用方法详细

    IOS--UIDatePicker 时间选择器 的使用方法详细 // 主要有下面四种类型:   // 日期显示. // 日期和时间显示. // 时间显示. // 倒计时选择       // UIDa ...

  4. iOS中UIPickerView常见属性和方法的总结

    UIPickerView是iOS中的原生选择器控件,使用方便,用法简单,效果漂亮. @property(nonatomic,assign) id<UIPickerViewDataSource&g ...

  5. jQuery选择器和选取方法 http://www.cnblogs.com/MaxIE/p/4078869.html

    我们已经使用了带有简单Css选择器的jQuery选取函数:$().现在是时候深入了解jQuery选择器语法,以及一些提取和扩充选中元素集的方法了. 一.jQuery选择器 在CSS3选择器标淮草案定义 ...

  6. JavaScript学习笔记-选择器集合调用方法

    <script type="text/javascript"> function uu(namePd) { //判断id var reId = new RegExp(/ ...

  7. jQuery选择器和选取方法

        我们已经使用了带有简单Css选择器的jQuery选取函数:$().现在是时候深入了解jQuery选择器语法,以及一些提取和扩充选中元素集的方法了. 一.jQuery选择器 在CSS3选择器标淮 ...

  8. jQuery 学习笔记(3)(内容选择器、attr方法、prop方法,类的操作)

    内容选择器: 1.$("div:empty"): 空的div元素 2.$("div:parent"): 非空div元素 3.$("div:contai ...

  9. jQuery选择器和选取方法.RP

    我们已经使用了带有简单Css选择器的jQuery选取函数:$().现在是时候深入了解jQuery选择器语法,以及一些提取和扩充选中元素集的方法了. 一.jQuery选择器 在CSS3选择器标淮草案定义 ...

随机推荐

  1. C#基础系列——委托和设计模式(二)

    前言:前篇 C#基础系列——委托实现简单设计模式 简单介绍了下委托的定义及简单用法.这篇打算从设计模式的角度去解析下委托的使用.我们知道使用委托可以实现对象行为(方法)的动态绑定,从而提高设计的灵活性 ...

  2. 关于 MonoDevelop on Linux 单步调试问题的解决

    在 MonoDevelop 中默认是关闭对外部程序集(.dll)的调试,可通过如下步骤来解决这个问题. 通过菜单[Edit]-[Preferences]-[Debugger]进入到调试器的设置页,把“ ...

  3. C#线程池使用

    bool stop; private void button3_Click(object sender, EventArgs e) { if(button3.Text=="线程池" ...

  4. mysql的基本命令行操作

    mysql>CREATE DATABASE imooc; //创建数据库 mysql> USE imooc ;//选择数据库 mysql> SELECT DATABASE();//查 ...

  5. AOPR破解的密码复制的方法

    Advanced Office Password Recovery是一款office密码破解工具,简称AOPR.使用过Advanced Office Password Recovery的用户都知道成功 ...

  6. javascript变量声明 及作用域

    javascript变量声明提升(hoisting) http://openwares.net/js/javascript_declaration_hoisting.html 可能要FQ一下 java ...

  7. a版本冲刺第一天

    队名:Aruba   队员: 黄辉昌 李陈辉 林炳锋 鄢继仁 张秀锋 章  鼎 学号 昨天完成的任务 今天做的任务 明天要做的任务 困难点 体会 408 学习测试文档的编写 继续学习并借鉴,开始着手写 ...

  8. java集合学生管理系统

    //student.java package com.sran.www; import java.util.Arrays; import java.util.Scanner; public class ...

  9. Palindrome Index

    传送门: Palindrome Index Problem Statement You are given a string of lower case letters. Your task is t ...

  10. Hibernate的关联映射关系

    一:多对一 <many-to-one 1.name:当前类的属性名(关联映射的类) 2.column:属性多对应的类的对应的表的外键(连接条件) 3.class:属性所对应的类的权限定名 4.n ...