zoukankan      html  css  js  c++  java
  • UIDatePicker应用 常用属性和方法

     1 #import "ViewController.h"
     2 
     3 @interface ViewController ()
     4 @property(strong,nonatomic)UIDatePicker * datepicker;
     5 -(void)UpdataTime;
     6 @end
     7 
     8 @implementation ViewController
     9 
    10 - (void)viewDidLoad {
    11     [super viewDidLoad];
    12     // Do any additional setup after loading the view, typically from a nib.
    13     self.datepicker = [[UIDatePicker alloc]initWithFrame:CGRectMake(10, 100, 350, 100)];
    14     self.datepicker.backgroundColor = [UIColor whiteColor];
    15     self.datepicker.datePickerMode = UIDatePickerModeDateAndTime;
    16     //设置地区,即显示的语言
    17     self.datepicker.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"zh_Hans_CN"];
    18     //设置当前日历
    19     [self.datepicker setCalendar:[NSCalendar currentCalendar]];
    20     //使得时间和系统同步
    21     [self.datepicker setTimeZone:[NSTimeZone systemTimeZone]];
    22     
    23     [self.datepicker setDate:[NSDate date] animated:YES];
    24     
    25     [self.datepicker addTarget:self action:@selector(UpdataTime) forControlEvents:UIControlEventValueChanged];
    26     [self.view addSubview:self.datepicker];
    27     
    28     
    29 }
    30 -(void)UpdataTime
    31 {
    32     [self.datepicker setDate:[NSDate date] animated:YES];
    33 }
    34 - (void)didReceiveMemoryWarning {
    35     [super didReceiveMemoryWarning];
    36     // Dispose of any resources that can be recreated.
    37 }
    38 
    39 @end
    View Code

    1、常用属性

    //设置pickerview的显示模式

    self.datepicker.datePickerMode = UIDatePickerModeDateAndTime;

    其中UIDatePickerModeCountDownTimer 是倒计时模式,需用到

    countDownDuration这个属性

    //设置地区,即显示的语言

    self.datepicker.locale = [[NSLocale alloc]initWithLocaleIdentifier:@"zh_Hans_CN"];

    //设置当前日历

    [self.datepicker setCalendar:[NSCalendar currentCalendar]];

    //使得时间和系统同步

    [self.datepicker setTimeZone:[NSTimeZone systemTimeZone]];

    //

    date属性可读可写,可以从pickerview上读取数据显示到其他上面

    //目标动作回调,实时监听数据更新

    [self.datepicker addTarget:self action:@selector(UpdataTime) forControlEvents:UIControlEventValueChanged];

    2、方法

    //设置时间

    self.datepicker setDate:[NSDate date] animated:YES];

  • 相关阅读:
    Linux运维常见故障排查和处理的技巧汇总
    React 页面开发服务规范抽象
    解决 NVM 安装 Node 版本出现 TLS 问题
    解决部署 React 框架 Next.js 到 IIS 上刷新页面出现 404 问题
    正则表达式
    rsa加解密代码实现
    zookeeper介绍(5)快速入门教程
    yii2-adminlte-asset中MenuHelper 菜单伸缩问题
    yii2-admin autocomplete 输出弹出框位置不对
    php curl模拟常用的请求
  • 原文地址:https://www.cnblogs.com/ylg-----/p/4772808.html
Copyright © 2011-2022 走看看