带有“完成"的 UIDatePicker按钮 [英] UIDatePicker with "done" button

查看:22
本文介绍了带有“完成"的 UIDatePicker按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在我的日期选择器中添加一个完成"按钮,如下图所示:

I need to add a "done" button to my date picker like in this image:

这是我的代码:

-(IBAction)chooseDate:(id)sender{
self.datepicker= [[UIDatePicker alloc] initWithFrame:CGRectMake(0, 0, 320, 216)];
    self.datepicker.datePickerMode = UIDatePickerModeDate;
    datepicker.backgroundColor = Rgb2UIColor(52, 170, 220);

    [self.btnDone
                addTarget:self
                action:@selector(SetDatePickerTime:)
                forControlEvents:UIControlEventTouchDown];

 [self.view addSubview:self.datepicker];
}

推荐答案

创建一个日期选择器,然后将其添加为相关字段的输入视图 (self.fieldInQuestion.inputView = datePicker).接下来,创建一个 UIToolBar(高度 44),上面有 UIBarButton 项目,标题为Done"、自身目标和一个选择器(例如@selector(done)).将此添加为您将日期选择器设为输入视图的同一字段的输入附件视图 (self.fieldInQuestion.inputAccessoryView = UIToolbarInstance).在选择器方法中(-(void)done 在上面的例子中),确保你使用 [self.fieldInQuestion resignFirstResponder] 并且它会关闭它.

Create a date picker, then add it as the input view of the field in question (self.fieldInQuestion.inputView = datePicker). Next, create a UIToolBar (height 44) with UIBarButton Item on it with the title "Done", target of self, and a selector (ex. @selector(done)). Add this as the input accessory view of the same field you made the date picker an input view for (self.fieldInQuestion.inputAccessoryView = UIToolbarInstance). In the selector method (-(void)done in the example above), make sure you use [self.fieldInQuestion resignFirstResponder] and it will dismiss it.

这篇关于带有“完成"的 UIDatePicker按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆