码迷,mamicode.com
首页 > 其他好文 > 详细

085设置日期选择器中的时间间隔

时间:2015-06-15 22:01:47      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:

效果如下:

技术分享

ViewController.h

1 #import <UIKit/UIKit.h>
2 
3 @interface ViewController : UIViewController
4 @end

ViewController.m

 1 #import "ViewController.h"
 2 
 3 @interface ViewController ()
 4 - (void)layoutUI;
 5 - (void)pickerDidChange:(UIDatePicker *)sender;
 6 @end
 7 
 8 @implementation ViewController
 9 
10 - (void)viewDidLoad {
11     [super viewDidLoad];
12     
13     [self layoutUI];
14 }
15 
16 - (void)didReceiveMemoryWarning {
17     [super didReceiveMemoryWarning];
18     // Dispose of any resources that can be recreated.
19 }
20 
21 - (void)layoutUI {
22     UIDatePicker *datePChoice = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
23     datePChoice.center = self.view.center;
24     //设置时间间隔为30分钟,要求必须被60整除的正整数
25     datePChoice.minuteInterval = 30;
26     
27     [datePChoice addTarget:self
28                     action:@selector(pickerDidChange:)
29           forControlEvents:UIControlEventValueChanged];
30     [self.view addSubview:datePChoice];
31 }
32 
33 - (void)pickerDidChange:(UIDatePicker *)sender {
34     NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
35     [formatter setDateFormat:@"yyyy/MM/dd HH:mm"]; //2015/04/19 13:42
36     NSString *strCurrentDate = [formatter stringFromDate:sender.date];
37     
38     UIAlertView *alertV = [[UIAlertView alloc] initWithTitle:@"选择的日期"
39                                                      message:strCurrentDate
40                                                     delegate:nil
41                                            cancelButtonTitle:nil
42                                            otherButtonTitles:@"确定", nil];
43     [alertV show];
44 }
45 
46 @end

 

085设置日期选择器中的时间间隔

标签:

原文地址:http://www.cnblogs.com/huangjianwu/p/4579219.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!