#import "ViewController.h"
@interface ViewController ()
//时间选择器
@property (retain)UIDatePicker* datePicker;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
//实例化时间选择器
_datePicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(0, 200, 320, 100)];
//设置显示风格样式
_datePicker.datePickerMode = UIDatePickerModeDate;
//设置最小时间
_datePicker.minimumDate = [NSDate dateWithTimeIntervalSinceNow:-50*360*24*60*60];
//设置当前时间
_datePicker.date = [NSDate date];
//设置最大时间
_datePicker.maximumDate = [NSDate date];//[NSDate dateWithTimeIntervalSinceNow:100*360*24*60*60];
[self.view addSubview:_datePicker];
UIButton* btn =[UIButton buttonWithType:UIButtonTypeCustom];
btn.frame = CGRectMake(0, 20, 50, 50);
btn.backgroundColor = [UIColor cyanColor];
[btn addTarget:self action:@selector(btnAction:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btn];
}
-(void)btnAction:(UIButton*)sender
{
NSLog(@"时间按钮。。。。。。。。");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
UIDatePicker时间选择器
最新推荐文章于 2023-06-14 10:25:28 发布
本文详细介绍了如何在iOS应用中使用UIDatePicker组件来实现时间选择功能,包括设置日期范围、选择模式以及获取用户选定的日期等操作,是iOS开发者的实用教程。
679

被折叠的 条评论
为什么被折叠?



