IOS 7 Study - UIDatePicker
Picking the Date and Time with UIDatePicker
effect:

1. declaring a property of type UIDatePicker
#import "ViewController.h" @interface ViewController () @property (nonatomic, strong) UIDatePicker *myDatePicker; @end @implementation ViewController ...
2. instantiate the date picker
- (void)viewDidLoad{
  [super viewDidLoad];
  self.myDatePicker = [[UIDatePicker alloc] init];
  self.myDatePicker.center = self.view.center;
  [self.view addSubview:self.myDatePicker];
}
3. add receiver target
Just like the UISwitch class, a date picker sends action messages to its targets whenever
the user has selected a different date. To respond to these messages, the receiver must
add itself as the target of the date picker, using the addTarget:action:forControlEvents
- (void)viewDidLoad{
  [super viewDidLoad];
  self.myDatePicker = [[UIDatePicker alloc] init];
  self.myDatePicker.center = self.view.center;
  [self.view addSubview:self.myDatePicker];
  [self.myDatePicker addTarget:self
     action:@selector(datePickerDateChanged:)
     forControlEvents:UIControlEventValueChanged];
}
4. accessing the date
// you can attempt to retrieve its currently selected date using its date property
NSDate *currentDate = self.myDatePicker.date;
NSLog(@"Date = %@", currentDate);
// every time the user changes the date, get a message from the date picker
- (void) datePickerDateChanged:(UIDatePicker *)paramDatePicker{
  if ([paramDatePicker isEqual:self.myDatePicker]){
    NSLog(@"Selected date = %@", paramDatePicker.date);
  }
}
A date picker also lets you set the minimum and the maximum dates that it can display.
For this, let’s first switch our date picker mode to UIDatePickerModeDate and then,
using the maximumDate and the minimumDate properties, adjust this range:
- (void)viewDidLoad{
  [super viewDidLoad];
  self.myDatePicker = [[UIDatePicker alloc] init];
  self.myDatePicker.center = self.view.center;
  self.myDatePicker.datePickerMode = UIDatePickerModeDate;
  [self.view addSubview:self.myDatePicker];
  NSTimeInterval oneYearTime =  *  *  * ;
  NSDate *todayDate = [NSDate date];
  NSDate *oneYearFromToday
    = [todayDate dateByAddingTimeInterval:oneYearTime];
  NSDate *twoYearsFromToday
    = [todayDate dateByAddingTimeInterval: * oneYearTime];
  self.myDatePicker.minimumDate = oneYearFromToday;
  self.myDatePicker.maximumDate = twoYearsFromToday;
}
If you want to use the date picker as a countdown timer, you must set your date picker
mode to UIDatePickerModeCountDownTimer and use the countDownDuration property
of the date picker to specify the default countdown duration.
- (void)viewDidLoad{
  [super viewDidLoad];
  self.myDatePicker = [[UIDatePicker alloc] init];
  self.myDatePicker.center = self.view.center;
  self.myDatePicker.datePickerMode = UIDatePickerModeCountDownTimer;
  [self.view addSubview:self.myDatePicker];
  NSTimeInterval twoMinutes =  * ;
  [self.myDatePicker setCountDownDuration:twoMinutes];
}
Run Result:

IOS 7 Study - UIDatePicker的更多相关文章
- iOS开发中UIDatePicker控件的使用方法简介
		
iOS上的选择时间日期的控件是这样的,左边是时间和日期混合,右边是单纯的日期模式. 您可以选择自己需要的模式,Time, Date,Date and Time , Count Down Timer四 ...
 - IOS 7 Study - UIViewController
		
Presenting and Managing Views with UIViewController ProblemYou want to switch among different views ...
 - iOS学习之UIDatePicker控件使用
		
iOS上的选择时间日期的控件是这样的,左边是时间和日期混合,右边是单纯的日期模式. , 您可以选择自己需要的模式,Time, Date,Date and Time , Count Down Ti ...
 - IOS 7 Study - Displaying an Image on a Navigation Bar
		
ProblemYou want to display an image instead of text as the title of the current view controlleron th ...
 - IOS 7 Study - Manipulating a Navigation Controller’s Array of View
		
ProblemYou would like to directly manipulate the array of view controllers associated with aspecific ...
 - IOS 7 Study - Implementing Navigation with UINavigationController
		
ProblemYou would like to allow your users to move from one view controller to the other witha smooth ...
 - IOS 7 Study - UIActivityViewController(Presenting Sharing Options)
		
You want to be able to allow your users to share content inside your apps with theirfriends, through ...
 - IOS 7 Study - UISegmentedControl
		
You would like to present a few options to your users from which they can pick anoption, through a U ...
 - 解析iOS开发中的FirstResponder第一响应对象
		
1. UIResonder 对于C#里所有的控件(例如TextBox),都继承于Control类.而Control类的继承关系如下: 代码如下: System.Object System.Marsha ...
 
随机推荐
- Golang 绘图基础 -绘制简单图形
			
前一节讲的是 绘图到不同输出源,请看地址: http://www.cnblogs.com/ghj1976/p/3440856.html 上一节的例子效果是通过设置每一个点的的RGBA属性来实现的,这是 ...
 - bjfu1281
			
思路挺简单的,但因为需要处理大数,所以就比较耗代码了. /* * Author : ben */ #include <cstdio> #include <cstdlib> #i ...
 - Linux基本命令(6)线上查询的命令
			
线上查询的命令 命令 功能 man 查询和解释一个命令的使用方法,以及这个命令的说明事项 locate 定位文件和目录 whatis 寻找某个命令的含义 6.1 man命令 man命令用来查询和解释一 ...
 - Fisher information matrix笔记
			
在看FK论文时,fisher information matrix是必须理解的. 从维基百科查阅到,Fisher information matrix是用利用最大似然函数估计来计算方差矩阵. 来源于: ...
 - 使用最小堆来完成k路归并    6.5-8
			
感谢:http://blog.csdn.net/mishifangxiangdefeng/article/details/7668486 声明:供自己学习之便而收集整理 题目:请给出一个时间为O(nl ...
 - STL map详细用法和make_pair函数
			
今天练习华为上机测试题,遇到了map的用法,看来博客http://blog.csdn.net/sprintfwater/article/details/8765034:感觉很详细,博主的其他内容也值得 ...
 - xcode import<xx/xx.h> 头文件报错
			
最近一直在写Android程序,有点久没用xcode,在写一个项目准备把 UI7Kit导进去,将iOS 7的界面适配到低版本的时候,出现了这么一个蛋疼的问题.稍微查了一下,新建项目的时候想先做一个li ...
 - cocos中添加显示文字的三种方式(CCLabelTTF 、CCLabelBMFont 和CCLabelAtlas)
			
CCLabelTTF CCLabelTTF 每次调用 setString (即改变文字)的时候,一个新的OPENGL 纹理将会被创建..这意味着setString 和创建一个新的标签一样慢. 这个类使 ...
 - Controlling GameObjects Using Components
			
[Accessing Components] The most common case is where a script needs access to other Components attac ...
 - Azure中国版  制作镜像  捕捉镜像
			
因为项目需要需要部署多台功能一样的服务器,简单来说是多台nginx服务器.如果按照原始的做法,是新建vm,然后一台台部署相关服务. 现在Azrue已经可以通过捕获镜像的方式创建vm镜像模板,然后按照创 ...