第十三篇 - UIDatePicker

初始化

UIDatePicker *dateView = [[UIDatePicker alloc] init];

 

添加事件监听

[dateView addTarget:self action:@selector(click:) forControlEvents:UIControlEventValueChanged];

 

获取当前选中的时间

- (void)click:(UIDatePicker *)sender{

     NSDateFormatter *df = [[NSDateFormatter alloc] init];

    df.timeZone = [NSTimeZone systemTimeZone];//系统所在时区

    df.dateFormat = @"yyyy-MM-dd HH:mm:ss";

    NSString *systemTimeZoneStr =  [df stringFromDate:sender.date];

    NSLog(@"%@",systemTimeZoneStr);

}

 以下来自:http://my.oschina.net/u/2340880/blog/464715

 

 

@property (nonatomic) UIDatePickerMode datePickerMode; 

设置控件模式,枚举如下:

?
1
2
3
4
5
6
typedef NS_ENUM(NSInteger, UIDatePickerMode) {
    UIDatePickerModeTime,           //时间模式,显示时分和上下午
    UIDatePickerModeDate,           //日期模式显示年月日
    UIDatePickerModeDateAndTime,    //时间和日期模式,显示月日星期,时分上下午
    UIDatePickerModeCountDownTimer, //计时模式,显示时和分
};

@property (nonatomic, retain) NSLocale   *locale;

设置本地化环境

@property (nonatomic, copy)   NSCalendar *calendar;

设置日历

@property (nonatomic, retain) NSTimeZone *timeZone;

设置时区

@property (nonatomic, retain) NSDate *date;  

设置当前时间

@property (nonatomic, retain) NSDate *minimumDate;

设置最小时间点

@property (nonatomic, retain) NSDate *maximumDate;

设置最大时间点

@property (nonatomic) NSTimeInterval countDownDuration;

只适用于计时模式,设置时间

@property (nonatomic) NSInteger      minuteInterval; 
设置每一格的时间差

- (void)setDate:(NSDate *)date animated:(BOOL)animated;

设置到一个时间,有动画效果

 

 

转载于:https://www.cnblogs.com/kinghx/p/5303828.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值