標籤:des c style class blog code
一、案例介紹:點擊螢幕中的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]; }