zoukankan      html  css  js  c++  java
  • UIDatePicker

     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
  • 相关阅读:
    聊聊、Spring 第一篇
    聊聊、Nginx 初始化日志文件
    聊聊、Nginx 参数合法性
    聊聊、Nginx GDB与MAIN参数
    聊聊、Nginx 初始化错误信息
    聊聊、Nginx GDB与MAIN
    聊聊、Nginx 安装启动
    聊聊、Zookeeper Windows启动
    Python使用列表推导式实现九九乘法和九九加法表
    Linux环境下后台运行Django项目
  • 原文地址:https://www.cnblogs.com/lantu1989/p/4612052.html
Copyright © 2011-2022 走看看