在UIPickerview上显示完成按钮 [英] display done button on UIPickerview
本文介绍了在UIPickerview上显示完成按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在 viewDidLoad
方法中编写了以下代码:
I have written the following code in the viewDidLoad
method:
categoryPickerView=[[UIPickerView alloc]init];
categoryPickerView.alpha = 0;
[self.view addSubview:categoryPickerView];
categoryPickerView.delegate=self;
categoryPickerView.tag=1;
并调用此方法隐藏选择器视图
and called this method to hide picker view
- (IBAction)hidePickerView:(id)sender {
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.6];
CGAffineTransform transfrom = CGAffineTransformMakeTranslation(0, 200);
categoryPickerView.transform = transfrom;
categoryPickerView.alpha = categoryPickerView.alpha * (-1) + 1;
[UIView commitAnimations];
}
我的问题是我想在选择器上显示完成按钮视图和选择器视图应隐藏在按钮单击上。
My problem is that I want to display a "Done" button on a picker view and the picker view should hide on button click.
推荐答案
您可以使用此代码,
UIToolbar *toolBar= [[UIToolbar alloc] initWithFrame:CGRectMake(0,0,320,44)];
[toolBar setBarStyle:UIBarStyleBlackOpaque];
UIBarButtonItem *barButtonDone = [[UIBarButtonItem alloc] initWithTitle:@"Done"
style:UIBarButtonItemStyleBordered target:self action:@selector(changeDateFromLabel:)];
toolBar.items = @[barButtonDone];
barButtonDone.tintColor=[UIColor blackColor];
[pickerView addSubview:toolBar];
//(or)pickerView.inputAccessoryView = toolBar;
并为设置按钮操作方法changeDateFromLabel:
-(void)changeDateFromLabel:(id)sender
{
[[your UI Element] resignFirstResponder];
}
这篇关于在UIPickerview上显示完成按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文