ios – 在UIPickerview上显示完成按钮

前端之家收集整理的这篇文章主要介绍了ios – 在UIPickerview上显示完成按钮前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在viewDidLoad方法中编写了以下代码
categoryPickerView=[[UIPickerView alloc]init];
categoryPickerView.alpha = 0;
[self.view addSubview:categoryPickerView];
categoryPickerView.delegate=self;
categoryPickerView.tag=1;

并称此方法隐藏选择器视图

- (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];
}

我的问题是我想在选择器视图上显示一个“完成”按钮,并且选择器视图应该隐藏在按钮上.

解决方法

你可以使用这段代码,
UIToolbar *toolBar= [[UIToolbar alloc] initWithFrame:CGRectMake(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];
}
原文链接:https://www.f2er.com/iOS/337417.html

猜你在找的iOS相关文章