• 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
  • 相关阅读:
    Odoo13在Win10(专业版)中的配置
    我在博客园安家了
    2012笔记
    你给我好好发邮件行不行
    事务经典例子
    轻松实现SQL Server与Access、Excel数据表间的导入导出
    SQL大全
    小笔记
    性能优化
    程序中的异常和错误处理
  • 原文地址:https://www.cnblogs.com/lantu1989/p/4612052.html
Copyright © 2020-2023  润新知