gpt4 book ai didi

ios - 如何在uiactionsheet中管理uipickerview

转载 作者:行者123 更新时间:2023-11-29 03:43:18 24 4
gpt4 key购买 nike

我正在尝试在 UIActionSheet 中显示 UIPickerView 。从下面提到的代码来看,它在纵向模式下工作得很好,但在横向模式下看起来是有线的。 (我的应用程序也支持 iPhone 4/5 n 横向)。 我做错了什么?

 actionSheet = [[UIActionSheet alloc] initWithTitle:nil
delegate:nil
cancelButtonTitle:nil
destructiveButtonTitle:nil
otherButtonTitles:nil];

[actionSheet setActionSheetStyle:UIActionSheetStyleBlackTranslucent];


CGRect pickerFrame=CGRectMake(0, 40, 0, 0);

UIPickerView *pickerView = [[UIPickerView alloc] initWithFrame:pickerFrame];
pickerView.showsSelectionIndicator = YES;
pickerView.dataSource = self;
pickerView.delegate = self;


[actionSheet addSubview:pickerView];

UISegmentedControl *closeButton = [[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObject:@"OK"]];
closeButton.momentary = YES;
closeButton.frame = CGRectMake(260, 7.0f, 50.0f, 30.0f);
closeButton.segmentedControlStyle = UISegmentedControlStyleBar;
closeButton.tintColor = [UIColor blackColor];
[closeButton addTarget:self action:@selector(dismissActionSheet:) forControlEvents:UIControlEventValueChanged];

[actionSheet addSubview:closeButton];
[actionSheet showInView:self.view];
[actionSheet setBounds:CGRectMake(0, 0, 320, 485)];

enter image description here

最佳答案

终于找到解决方案了

首先,我必须像我提到的那样设置选择器 View 的宽度

CGRect pickerFrame=CGRectMake(0, 40, 0, 0);

所以它可以像

CGRect pickerFrame=CGRectMake(0, 40, 320, 0);

我找到了一个更好的解决方案:

只需单击文本字段即可调用操作表中的选取器 View :

self.textField.inputView = yourCustomView;

关于ios - 如何在uiactionsheet中管理uipickerview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18053684/

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