zoukankan      html  css  js  c++  java
  • 日期选择器

      birthDate = [[UIDatePicker alloc] initWithFrame:CGRectMake(0,500/2,self.view.frame.size.width, 88/2)];
                birthDate.datePickerMode = UIDatePickerModeDate;// 设置只显示日期
                [birthDate addTarget:self action:@selector(setBirthDate:) forControlEvents:UIControlEventValueChanged];
                [self.view addSubview:birthDate];
                
                //设置toolbar
                pickerToolbar=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 470/2, self.view.frame.size.width, 30)];
                [pickerToolbar setBackgroundColor:[UIColor clearColor]];
                UIBarButtonItem* sureItem=[[UIBarButtonItem alloc]initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:@selector(hiddenPicker:)];
                sureItem.tag = 10;
                UIBarButtonItem* cancelItem=[[UIBarButtonItem alloc]initWithTitle:@"取消" style:UIBarButtonItemStyleDone target:self action:@selector(hiddenPicker:)];
                UIBarButtonItem* flexItem=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
                flexItem.tag = 11;
    //            pickerToolbar.hidden=YES;
                pickerToolbar.items=@[sureItem,flexItem,cancelItem];
    
                [self.view addSubview:pickerToolbar];
    
    /*
     *@brief 选择出生日期方法
     **
     */
    - (void)setBirthDate:(id)sender
    {
        NSLog(@"设置出生日期");
        // 获取用户通过UIDatePicker设置的日期和时间
        NSDate *selected = [birthDate date];
        // 创建一个日期格式器
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        // 为日期格式器设置格式字符串
        [dateFormatter setDateFormat:@"MM月dd日"];
        // 使用日期格式器格式化日期、时间
        destDateString = [dateFormatter stringFromDate:selected];
        NSLog(@"string === %@",destDateString);
        [personMessageArr replaceObjectAtIndex:5 withObject:destDateString];
        NSLog(@"%@",personMessageArr);
        /// 调用修改日期接口
        
        
    
    }
    
  • 相关阅读:
    求100内的数和
    汉诺塔(印度传说)
    ORA-06502:PL/SQL:数字或值错误:数值精度太高
    触发器的编写
    mysql改密码
    LeetCode-238 Product of Array Except Self
    LeetCode-236 Lowest Common Ancestor of a Binary Tree
    LeetCode-233 Number of Digit One
    LeetCode-230 Kth Smallest Element in a BST
    LeetCode-229 Majority Element II
  • 原文地址:https://www.cnblogs.com/angongIT/p/4536696.html
Copyright © 2011-2022 走看看