我想在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)];
答案 0 :(得分:1)
最后我得到了解决方案
首先,我必须像我提到的那样设置选择器视图的宽度
CGRect pickerFrame=CGRectMake(0, 40, 0, 0);
所以它可以像
CGRect pickerFrame=CGRectMake(0, 40, 320, 0);
我找到了一个更好的解决方案:
只需点击文字字段即可在操作表中调用选择器视图:
self.textField.inputView = yourCustomView;