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
  • 相关阅读:
    获取office版本
    SQL中判断字符串中包含字符的方法
    wpf 多表头
    webservice MaxReceivedMessageSize :已超过传入消息(65536)的最大消息大小配额
    QQ检测登陆及QQ协议
    ssl-openssl简介
    抓包及分析(wireshark&tcpdump)
    Git的一些东西(后续补充)
    SSH实现隧道功能穿墙
    Nmap参考指南(Man Page)
  • 原文地址:https://www.cnblogs.com/lantu1989/p/4612052.html
Copyright © 2011-2022 走看看