码迷,mamicode.com
首页 > 其他好文 > 详细

UIDatePicker

时间:2015-04-20 11:12:26      阅读:114      评论:0      收藏:0      [点我收藏+]

标签:uidatepicker

<span style="background-color: rgb(51, 204, 255);">//
//  NSDatePickerViewController.m
//  NSDatePicker
//
//  Created by xiaoyao on 15/4/20.
//  Copyright (c) 2015年 lijien. All rights reserved.
//

#import "NSDatePickerViewController.h"

@interface NSDatePickerViewController () {
  UIDatePicker *_datePicker;
  UILabel      *_dateLabel;
}

@end

@implementation NSDatePickerViewController

- (void)viewDidLoad {
  [super viewDidLoad];
 
  CGFloat width = self.view.frame.size.width;
  CGFloat height = self.view.frame.size.height;
  
  _datePicker = [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 200, width, height)];
  [self.view addSubview:_datePicker];
  
  // 选择datePicker的模式
  // 有三种模式 日期模式、时间日期模式、时间模式、计数器倒计时模式
  _datePicker.datePickerMode = UIDatePickerModeDate;
  
  NSDate *date = _datePicker.date;
  NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
  [dateFormatter setDateFormat:@"YYYY-MM-DD HH:mm:ss"];
  
  _dateLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 400, width, height)];
  _dateLabel.textColor = [UIColor lightGrayColor];
  _dateLabel.text = [dateFormatter stringFromDate:date];
  
}

- (void)didReceiveMemoryWarning {
  [super didReceiveMemoryWarning];
  // Dispose of any resources that can be recreated.
}
@end
</span>

UIDatePicker

标签:uidatepicker

原文地址:http://blog.csdn.net/u010606986/article/details/45147479

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