0

我正在尝试在 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)];

在此处输入图像描述

4

1 回答 1

1

最后我得到了解决方案

首先,我必须设置选择器视图的宽度,正如我所提到的

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

所以它可以像

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

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

只需通过单击文本字段来调用操作表中的选择器视图:

self.textField.inputView = yourCustomView;
于 2013-08-12T07:16:32.300 回答