IOS|IOS UIAlertController 弹出框中添加视图(例如日期选择器等等)
2019独角兽企业重金招聘Python工程师标准>>>
文章图片
UIDatePicker *datePicker = [[UIDatePicker alloc] init];
datePicker.datePickerMode = UIDatePickerModeDate;
UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"\n\n\n\n\n\n\n\n\n\n\n\n" message:nilpreferredStyle:UIAlertControllerStyleActionSheet];
[alert.view addSubview:datePicker];
UIAlertAction *ok = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
NSDateFormatter* dateFormat = [[NSDateFormatter alloc] init];
//实例化一个NSDateFormatter对象
[dateFormat setDateFormat:@"yyyy-MM-dd"];
//设定时间格式
NSString *dateString = [dateFormat stringFromDate:datePicker.date];
//求出当天的时间字符串
NSLog(@"%@",dateString);
}];
UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
}];
[alert addAction:ok];
[alert addAction:cancel];
[self presentViewController:alert animated:YES completion:^{ }];
需要注意的是,这里没有设置地区时间
[datePicker setLocale:[[NSLocale alloc]initWithLocaleIdentifier:@"zh_Hans_CN"]];
【IOS|IOS UIAlertController 弹出框中添加视图(例如日期选择器等等)】转载于:https://my.oschina.net/u/554046/blog/529301
推荐阅读
- 2020-04-07vue中Axios的封装和API接口的管理
- iOS中的Block
- 记录iOS生成分享图片的一些问题,根据UIView生成固定尺寸的分享图片
- EditText默认不获取焦点弹出键盘
- 2019-08-29|2019-08-29 iOS13适配那点事
- Hacking|Hacking with iOS: SwiftUI Edition - SnowSeeker 项目(一)
- iOS面试题--基础
- 接口|axios接口报错-参数类型错误解决
- iOS|iOS 笔记之_时间戳 + DES 加密
- iOS,打Framework静态库