码迷,mamicode.com
首页 > 移动开发 > 详细

iOS.UIKit.10.UIDatePicker

时间:2014-06-04 15:23:24      阅读:271      评论:0      收藏:0      [点我收藏+]

标签:des   c   style   class   blog   code   

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

bubuko.com,布布扣图01bubuko.com,布布扣图02

二、案例步骤:

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

bubuko.com,布布扣图03

2、Main.storyboard,如图04

bubuko.com,布布扣

3、CQ36ViewController.h

bubuko.com,布布扣
#import <UIKit/UIKit.h>

@interface CQ36ViewController : UIViewController

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

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

- (IBAction)onclick:(id)sender;

@end
bubuko.com,布布扣

4、CQ36ViewController.m

bubuko.com,布布扣
- (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];
                                      
}
bubuko.com,布布扣

 

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

iOS.UIKit.10.UIDatePicker

标签:des   c   style   class   blog   code   

原文地址:http://www.cnblogs.com/cqchen/p/3764997.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!