iOS.UIKit.10.UIDatePicker

一、案例介绍:点击屏幕中的UIButton,将在UIDatePicker选择的日期显示在UILabel中,如图01,02

图01图02

二、案例步骤:

1、选择Simple View Aplication,取名cq.36.日期选择器,如图03

图03

2、Main.storyboard,如图04

3、CQ36ViewController.h

#import <UIKit/UIKit.h>

@interface CQ36ViewController : UIViewController

@property (weak,nonatomic) IBOutlet UIDatePicker *datePicker;

@property (weak,nonatomic) IBOutlet UILabel *label;

- (IBAction)onclick:(id)sender;

@end

4、CQ36ViewController.m

- (IBAction)onclick:(id)sender
{
    NSDate *theDate = self.datePicker.date;
    NSLog(@"the date picked is: %@",[theDate descriptionWithLocale:[NSLocale currentLocale]]);
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    NSLog(@"the date format is: %@",[dateFormatter stringFromDate:theDate]);
    self.label.text = [dateFormatter stringFromDate:theDate];
                                      
}

 

iOS.UIKit.10.UIDatePicker,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。