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

UIDatePicker

时间:2015-06-30 23:36:55      阅读:172      评论:0      收藏:0      [点我收藏+]

标签:

 1 #import "AppDelegate.h"
 2 
 3 @interface AppDelegate ()
 4 @property (nonatomic,strong)UILabel *label;
 5 @end
 6 
 7 @implementation AppDelegate
 8 
 9 - (void)dealloc
10 {
11     self.label = nil;
12     self.window = nil;
13 }
14 
15 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
16     self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
17     // Override point for customization after application launch.
18     self.window.backgroundColor = [UIColor whiteColor];
19     
20     UIDatePicker *picker = [[UIDatePicker alloc] initWithFrame:CGRectZero];
21     picker.datePickerMode = UIDatePickerModeDateAndTime;
22     // 添加事件
23     [picker addTarget:self action:@selector(changeDateOfPicker:) forControlEvents:UIControlEventValueChanged];
24     [self.window addSubview:picker];
25     // 创建label
26     self.label = [[UILabel alloc] initWithFrame:CGRectMake(0, 300, [UIScreen mainScreen].bounds.size.width, 100)];
27     self.label.backgroundColor = [UIColor clearColor];
28     self.label.textAlignment = NSTextAlignmentCenter;
29     [self.window addSubview:self.label];
30     
31     [self.window makeKeyAndVisible];
32     return YES;
33 }
34 
35 - (void)changeDateOfPicker:(UIDatePicker *)sender
36 {
37     NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
38     [dateFormatter setDateFormat:@"Y/MM/dd H:mm:ss"];
39     NSString *dateString = [dateFormatter stringFromDate:[sender date]];
40     
41     self.label.text = dateString;
42 }
43 
44 
45 @end

 

UIDatePicker

标签:

原文地址:http://www.cnblogs.com/lantu1989/p/4612052.html

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