UIDatePicker
2016-07-26 16:33
381 查看
4000
我们需要首先需要设置为中国形式日期,通过属性Locale设置DatePicker的地区,即设置DatePicker显示的语言。
1.如果想查看跟踪所有可用的地区标识,取出想要的地区
2.设置日期选择控件的地区,中国地区标识是:"zh_Hans_CN"或者"zh_CN"
下面是常用的创建一个日期选择器方法:
文/若水V_V(简书作者)
原文链接:http://www.jianshu.com/p/c4f22a6d5f23
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
我们需要首先需要设置为中国形式日期,通过属性Locale设置DatePicker的地区,即设置DatePicker显示的语言。
1.如果想查看跟踪所有可用的地区标识,取出想要的地区
NSLog(@"%@", [NSLocale availableLocaleIdentifiers]);
2.设置日期选择控件的地区,中国地区标识是:"zh_Hans_CN"或者"zh_CN"
[datePicker setLocale:[[NSLocale alloc]initWithLocaleIdentifier:@"zh_Hans_CN"]];
下面是常用的创建一个日期选择器方法:
dateView = [[UIButton alloc] initWithFrame:self.view.bounds]; [self.view addSubview:dateView]; NSLog(@"%@", [NSLocale availableLocaleIdentifiers]); // 初始化UIDatePicker,旋转滚动选择日期类 UIDatePicker *datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 350, 320, 216)]; [datePicker setLocale:[[NSLocale alloc]initWithLocaleIdentifier:@"zh_CN"]]; // 设置时区 [datePicker setTimeZone:[NSTimeZone localTimeZone]]; // 设置当前显示时间 [datePicker setDate:[NSDate date] animated:YES]; // 设置显示最大时间(此处为当前时间) [datePicker setMaximumDate:[NSDate date]]; // 设置UIDatePicker的显示模式 [datePicker setDatePickerMode:UIDatePickerModeDate]; // 当值发生改变的时候调用的方法 [datePicker addTarget:self action:@selector(datePickerValueChanged:) forControlEvents:UIControlEventValueChanged]; [dateView addSubview:datePicker]; [dateView addTarget:self action:@selector(hideDateView) forControlEvents:UIControlEventTouchUpInside]; dateView.hidden = YES;
文/若水V_V(简书作者)
原文链接:http://www.jianshu.com/p/c4f22a6d5f23
著作权归作者所有,转载请联系作者获得授权,并标注“简书作者”。
相关文章推荐
- iOS流布局UICollectionView系列三——使用FlowLayout进行更灵活布局
- UIResponder的响应链方法
- "mkimage" command not found - U-Boot images will not be built
- 关于LayoutInflater类inflate(intresource, ViewGroup root, boolean attachToRoot)方法三个参数的含义
- ueditor UEditor的setContent的时候报错
- Fragment简单入门
- iOS流布局UICollectionView系列二——UICollectionView的代理方法
- sudo: must be setuid root解决办法
- iOS UITableViewCell滑动删除
- 图片渲染问题
- 美工 UI尺寸规范总结-iphone,android,ipad
- 异步消息处理机制(Handler 、 Looper 、MessageQueue)源码解析
- 新建了个用户 结果还sudo报错:sudo: /usr/bin/sudo must be owned by uid 0 and have the setuid bit set
- UltraEdit (UEStudio)使用技巧
- EasyUI数据表格之二
- EasyUI数据表格之二
- EasyUI数据表格之二
- java.lang.IllegalArgumentException: Control character in cookie value or attribute.
- Vrui 增加自定义事件
- CodeForces 289B Polo the Penguin and Matrix