UIDatePicker

作者: 无邪8 | 来源:发表于2018-05-21 16:06 被阅读6次

    一、简介

    <<UIDatePicker这个类的对象让用户可以在多个车轮上选择日期和时间。iPhone手机上的‘时钟’应用程序中的时间与闹铃中便使用了该控件。使用这个控件时,如果你能配置正确,当用户滚动车轮到一个新的日期或者时间上时,利用UIControlEventValueChanged触发事件

    <<继承关系:UIDatePicker-->UIControl-->UIView-->UIResponder-->NSObject

    格式为

    1-->初始化(作用)

    typedef NS_OPTIONS(NSUInteger, UIDataDetectorTypes) {

    UIDataDetectorTypePhoneNumber                                        = 1 << 0, //检测电话

    UIDataDetectorTypeLink                                              = 1 << 1, //检测网址和邮箱

    UIDataDetectorTypeAddress NS_ENUM_AVAILABLE_IOS(4_0)                = 1 << 2, // 检测地址

    UIDataDetectorTypeCalendarEvent NS_ENUM_AVAILABLE_IOS(4_0)          = 1 << 3, // 检测日历

    UIDataDetectorTypeShipmentTrackingNumber NS_ENUM_AVAILABLE_IOS(10_0) = 1 << 4, // 货物追踪号码检测

    UIDataDetectorTypeFlightNumber NS_ENUM_AVAILABLE_IOS(10_0)          = 1 << 5, // 班机号码检测

    UIDataDetectorTypeLookupSuggestion NS_ENUM_AVAILABLE_IOS(10_0)      = 1 << 6, //用户可能要查找的信息

    UIDataDetectorTypeNone          = 0,              // 禁用检测

    UIDataDetectorTypeAll          = NSUIntegerMax   // 检测所有类型链接

    } __TVOS_PROHIBITED;

    ;(如果属性有枚举类型的话,这里会有枚举类型说明

    self.webView.dataDetectorTypes =UIDataDetectorTypeAll;(这是具体的例子

    @property (nonatomic) UIDataDetectorTypes dataDetectorTypes NS_AVAILABLE_IOS(3_0);// UITextField 设置提示文字    (这是说明

    二、UIDatePicker的文本属性(属性的顺序与苹果API一致)

    1-->设置时间选择器的模式

    typedef NS_ENUM(NSInteger, UIDatePickerMode) {    

    UIDatePickerModeTime,           //时间模式,显示时分和上下午    UIDatePickerModeDate,           //日期模式显示年月日    UIDatePickerModeDateAndTime,    //时间和日期模式,显示月日星期,时分上下午    UIDatePickerModeCountDownTimer, //计时模式,显示时和分

    };

     datePicker.datePickerMode = UIDatePickerModeDate;

    @property (nonatomic) UIDatePickerMode datePickerMode; // 默认是 UIDatePickerModeDateAndTime

    2-->设置本地化环境

    [self.picker setLocale:[[NSLocale alloc]initWithLocaleIdentifier:@"zh_Hans_CN"]];  

    @property (nullable, nonatomic, strong) NSLocale *locale; // 默认是 [NSLocale currentLocale]. setting nil returns to default

    3-->日历属性

        [datePicker setCalendar:[NSCalendar currentCalendar]];

    @property (null_resettable, nonatomic, copy) NSCalendar *calendar; // 默认是[NSCalendar currentCalendar]. setting nil returns to default

    4--> 设置DatePicker的时区

    [datePicker setTimeZone:[NSTimeZone defaultTimeZone]];

    @property (nullable, nonatomic, strong) NSTimeZone *timeZone; // default is nil. use current time zone or time zone from calendar

    5-->设置DatePicker的日期。

        [datePicker setDate:[NSDate date]];

    @property (nonatomic, strong) NSDate *date; 

    6-->设置DatePicker的允许的最小日期

    self.datePicker.minimumDate = minDate;

    @property (nullable, nonatomic, strong) NSDate *minimumDate;

    备注:

    1.该属性值为NSDate对象,默认值是nil,nil意味着没有最小显示时间的约束。

    2.该属性与最大显示时间属性(maximumDate)结合,表示一个有效的时间范围。

    3.如果最小显示时间大于最大显示时间时,这两种性质都被忽略。

    4.在倒计时模式(UIDatePickerModeCountDownTimer)下,最小显示时间和最大显示时间这两个属性都会被忽略。

    7-->>设置DatePicker的允许的最大日期

        [myDatePicker setMaximumDate:maxDate];

    @property (nullable, nonatomic, strong) NSDate *maximumDate; 

    备注:

    1.该属性值为NSDate对象,默认值是nil,nil意味着没有最大显示时间的约束     

     2.该属性与最小显示时间属性(minimumDate)结合,表示一个有效的时间范围。

    3.如果最小显示时间大于最大显示时间时,这两种性质都被忽略。

    4.在倒计时模式(UIDatePickerModeCountDownTimer)下,最小显示时间和最大显示时间这两个属性都会被忽略。

    8-->设置倒计时秒数属性

     [myDatePicker setCountDownDuration:10 * 60];

    @property (nonatomic) NSTimeInterval countDownDuration; 

    备注:

    1.该属性设置倒计时需要倒计的秒数。

     2.如果时间选择器的时间模式不是倒计时模式,则该属性会被忽略。

    3.默认值是0.0,最大值为23:59(86399秒)。

    9-->设置每一格的时间差

        datePicker.minuteInterval = 15;

    @property (nonatomic) NSInteger minuteInterval; 

    备注:

    1.使用该属性设置由分钟车轮显示的时间间隔。

    2.间隔值必须均匀地分隔60,如果没有这样做,该属性将使用默认值为1。

     3.该属性值的范围是大于等于1,并小于等于30。

    10-->前进到history中的下个页面

    [webView goForward];

    - (void)goForward;

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

     [ datePicker setDate:maxDate animated:YES];

    - (void)setDate:(NSDate *)date animated:(BOOL)animated; // if animated is YES, animate the wheels of time to display the new date

    相关文章

      网友评论

        本文标题:UIDatePicker

        本文链接:https://www.haomeiwen.com/subject/fjtqjftx.html