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. 当Table中td内容为空时,显示边框的办法

    1. 在 table的css里面加: border-collapse:collapse;在 td 的css里面加: empty-cells:show; 2 .最简单的就是 在TD里写个    说明: ...

  2. 学python

    1.*和** def sum(*x): ans=0 for i in x: ans+=i return ans def haha(one,two): print(one,' ',two) print( ...

  3. 【jQuery示例】遍历表单数据并显示

    <!DOCTYPE html> <html> <head> <style> body, select { font-size:14px; } form ...

  4. IIS不支持apk文件下载

    类型添加为:.apk MIME类型中填写apk的MIME类型“ application/vnd.android.package-archive ”

  5. Android Studio NDK编程-环境搭建及Hello!

    一,下载 安装android-ndk开发包 NDK各个版本链接二,新建项目NDKDemo,选择空Activity就可以:(注:Android studio 2.2,可通过SDK Tools 添加LLD ...

  6. redis-设置密码

    1.通过配置文件设置密码 找到redis的安装目录中的如下文件 linux:/etc/redis.confwindows(我的windwos免安装版本):E:\redis\redis-2.4.5-wi ...

  7. TCP协议中的三次握手和四次挥手(图解)

    建立TCP需要三次握手才能建立,而断开连接则需要四次握手.整个过程如下图所示: 先来看看如何建立连接的. 首先Client端发送连接请求报文,Server段接受连接后回复ACK报文,并为这次连接分配资 ...

  8. 解决:Win 10安装软件时提示:文件系统错误 (-1073740940)

    1.win+R输入 gpedit.msc 2.左边计算机配置 windows设置——安全设置——本地策略——安全选项 3.在安全选项右边选择 用户账户控制:管理员批准模式中管理员的提升权限提示的行为, ...

  9. 【Codeforces715C&716E】Digit Tree 数学 + 点分治

    C. Digit Tree time limit per test:3 seconds memory limit per test:256 megabytes input:standard input ...

  10. 一、Daily Scrum Meeting【Alpha】------Clover

    [Alpha]Daily Scrum Meeting 第一次 [Alpha]Daily Scrum Meeting 第二次 [Alpha]Daily Scrum Meeting 第三次 [Alpha] ...