IOS 学习 日期选择器
2015-08-25 15:26
423 查看
(void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIDatePicker *dataPicker = [[UIDatePicker alloc] init];
[dataPicker setCenter:CGPointMake(self.view.frame.size.width * 0.5, self.view.frame.size.height * 0.5)];
[dataPicker setTag:1];
[self.view addSubview:dataPicker];
CGRect rect = CGRectMake(self.view.frame.size.width * 0.5, self.view.frame.size.height * 0.7, 100, 30);
UIButton *button = [[UIButton alloc] initWithFrame:rect];
[button setTitle:@”Select” forState:UIControlStateNormal];
[button setBackgroundColor:[UIColor purpleColor]];
[button addTarget:self action:@selector(getDate) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
-(void)getDate
{
UIDatePicker dataPicker = (UIDatePicker )[self.view viewWithTag:1];
NSDate *select = [dataPicker date];
NSDateFormatter *dataFormatter = [[NSDateFormatter alloc] init];
[dataFormatter setDateFormat:@”yyyy-MM-dd HH:mm”];
NSString *dateAndTime = [dataFormatter stringFromDate:select];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@”Date” message:dateAndTime delegate:self cancelButtonTitle:@”OK” otherButtonTitles:nil, nil];
[alert show];
}
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIDatePicker *dataPicker = [[UIDatePicker alloc] init];
[dataPicker setCenter:CGPointMake(self.view.frame.size.width * 0.5, self.view.frame.size.height * 0.5)];
[dataPicker setTag:1];
[self.view addSubview:dataPicker];
CGRect rect = CGRectMake(self.view.frame.size.width * 0.5, self.view.frame.size.height * 0.7, 100, 30);
UIButton *button = [[UIButton alloc] initWithFrame:rect];
[button setTitle:@”Select” forState:UIControlStateNormal];
[button setBackgroundColor:[UIColor purpleColor]];
[button addTarget:self action:@selector(getDate) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
}
-(void)getDate
{
UIDatePicker dataPicker = (UIDatePicker )[self.view viewWithTag:1];
NSDate *select = [dataPicker date];
NSDateFormatter *dataFormatter = [[NSDateFormatter alloc] init];
[dataFormatter setDateFormat:@”yyyy-MM-dd HH:mm”];
NSString *dateAndTime = [dataFormatter stringFromDate:select];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@”Date” message:dateAndTime delegate:self cancelButtonTitle:@”OK” otherButtonTitles:nil, nil];
[alert show];
}
相关文章推荐
- IOS 学习 TableView
- IOS 学习 gei post 同步 异步方法
- ios手势操作,四个基本事件与六个常用事件
- IOS 学习 多线程
- iOS 证书
- IOS 学习 自动换行与去除分割线
- IOS银行卡合法性校验
- iOS开发之构建Widget
- IOS 学习 创建主TabBar
- IOS 学习 创建表格的方法
- iOS利用通知(NSNotification)进行传值
- IOS 学习 模型初始化的方法
- IOS 学习 执行动画
- iOS 7 viewcontroller新增属性automaticallyAdjustsScrollViewInsets
- [iOS] #运行时编程# Block植入
- iOS 常用的宏定义
- iOS第三方框架集合
- IOS 学习记录 表格单元格放入缓存池
- IOS 学习 字典转模型
- ios自定义构造方法