gpt4 book ai didi

ios - 在 UIPickerview 上显示完成按钮

转载 作者:IT王子 更新时间:2023-10-29 08:13:02 24 4
gpt4 key购买 nike

我在viewDidLoad方法中写了如下代码:

categoryPickerView=[[UIPickerView alloc]init];
categoryPickerView.alpha = 0;
[self.view addSubview:categoryPickerView];
categoryPickerView.delegate=self;
categoryPickerView.tag=1;

并调用这个方法来隐藏选择器 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];
}

我的问题是我想在选择器 View 上显示一个“完成”按钮,并且选择器 View 应该在按钮单击时隐藏。

最佳答案

您可以使用此代码,

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

关于ios - 在 UIPickerview 上显示完成按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20883388/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com