首页 > 移动平台 > 详细

iOS.UIKit.10.UIDatePicker

时间:2014-06-04 15:22:19      阅读:437      评论:0      收藏:0      [点我收藏+]

一、案例介绍:点击屏幕中的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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!