UIToolBar以及日期选择器的基本用法
来源:互联网 发布:c语言小程序 编辑:程序博客网 时间:2024/06/06 10:57
// 添加个文本框
UITextField *textfield = [[UITextFieldalloc]initWithFrame:CGRectMake(100,350,200,30)];
[self.viewaddSubview:textfield];
textfield.backgroundColor= [UIColorgrayColor];
self.textfield= textfield;
// 弹出来一个datepicker, 默认有宽高
UIDatePicker *datepick = [[UIDatePickeralloc]init];
datepick.datePickerMode= UIDatePickerModeDate; // 设置显示模式
datepick.locale = [NSLocale localeWithLocaleIdentifier:@"zh-Hans"];//设置语言
// 添加监听事件
[datepick addTarget:selfaction:@selector(change:)forControlEvents:UIControlEventValueChanged];// 当日期变化的时候
// 设置文本框的inputview属性
textfield.inputView= datepick;
datepick.minimumDate= [NSDatedateWithTimeIntervalSince1970:0];//最大可选择时间
datepick.maximumDate= [NSDatedateWithTimeIntervalSinceNow:0];//最小可选择时间
//---------------------创建picker上面的工具条-----------------------------------
// 注意 默认在弹框上方,所以前3个参数没有作用,只有高度有用
UIToolbar *toolbar = [[UIToolbaralloc]initWithFrame:CGRectMake(0, 100, 20, 38)];;
// 设置背景颜色
toolbar.backgroundColor= [UIColorgreenColor];
// 创建一个item,确定按钮
UIBarButtonItem *item = [[UIBarButtonItemalloc]initWithTitle:@"确定"style:UIBarButtonItemStylePlaintarget:selfaction:@selector(endedit)];// 缩回键盘
// 创建个弹簧, 弹到右边去
UIBarButtonItem *fix = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpacetarget:nilaction:nil];
toolbar.tintColor= [UIColorblackColor];// 设置工具条上的文字颜色
toolbar.items = @[fix,item];
textfield.inputAccessoryView= toolbar; // 文本框的属性
}
// 滚动日期选择器的时候
- (void)change:(UIDatePicker*)datepick{
//格式化日期
NSDateFormatter *date = [[NSDateFormatteralloc]init];
date.dateFormat = @"yyyy/MM/dd";// 中间的/可以改变自己定义
// 转化成字符串
NSString *str1 = [date stringFromDate:datepick.date];
// 给文本框赋值
self.textfield.text= str1;
}
// 缩回键盘
- (void)endedit{
[self.viewendEditing:YES];
}
- (void)nextcontroller{
UIBarButtonItem *item = [[UIBarButtonItemalloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAddtarget:selfaction:@selector(click)];
self.navigationItem.rightBarButtonItem= item;
}
- (void)click{
KBbirthController*birth = [[KBbirthControlleralloc]init];
[self.navigationControllerpushViewController:birthanimated:YES];
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(100,100,200,200)];
[self.viewaddSubview:label];
label.numberOfLines= 0;
label.text = self.sqec;
self.view.backgroundColor= [UIColorwhiteColor];
}
0 0
- UIToolBar以及日期选择器的基本用法
- UIToolBar基本用法
- UIToolBar的用法
- 日期、时间选择器的基本使用
- Android 时间日期选择器的用法
- Android日期选择器用法
- UIDatePicker && UIToolbar【时期选择器】
- jquery基本选择器的用法解析
- JQuery基础之选择器的基本用法
- Android选择器-shape的基本用法
- Swift - 工具条(UIToolbar)的用法
- Jquery选择器基本用法
- 日期和时间选择器(DatePicker与TimePicker的用法)
- Bootstrap-datepicker日期时间选择器的常见用法总结
- 牛人写的日期选择器
- 很好的日期选择器
- jquery 的日期选择器
- 日期选择器的实现
- Hadoop/Yarn/MapReduce内存分配(配置)方案 .
- 【Android】AndroidManifest.xml 配置权限大全
- ClassLoader 详解及用途
- 异步同步数据Mario库简介
- ActionBar使用应用程序图标响应操作
- UIToolBar以及日期选择器的基本用法
- 《Android源码设计模式解析与实战》读书笔记(十八)
- Linux Shell 通配符、元字符、转义符使用实例介绍
- 深入理解同步/异步与阻塞/非阻塞区别
- SIGALRM信号会中断sleep
- xx-net从菜鸟到精通
- tomcat https 配置
- JDK动态代理原理及实现
- 博客声明