码迷,mamicode.com
首页 > 其他好文 > 详细

日期选择器

时间:2015-05-28 19:54:04      阅读:160      评论:0      收藏:0      [点我收藏+]

标签:

  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);
    /// 调用修改日期接口
    
    

}

 

日期选择器

标签:

原文地址:http://www.cnblogs.com/angongIT/p/4536696.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!