iOS.UIKit.10.UIDatePicker

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

iOS.UIKit.10.UIDatePicker图01iOS.UIKit.10.UIDatePicker图02

二、案例步骤:

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

iOS.UIKit.10.UIDatePicker图03

2、Main.storyboard,如图04

iOS.UIKit.10.UIDatePicker

3、CQ36ViewController.h

iOS.UIKit.10.UIDatePicker
#import <UIKit/UIKit.h>

@interface CQ36ViewController : UIViewController

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

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

- (IBAction)onclick:(id)sender;

@end
iOS.UIKit.10.UIDatePicker

4、CQ36ViewController.m

iOS.UIKit.10.UIDatePicker
- (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

 

iOS.UIKit.10.UIDatePicker,布布扣,bubuko.com

iOS.UIKit.10.UIDatePicker

上一篇:Android SDK上手指南 2:用户界面设计


下一篇:android开发中应该注意的问题