我正在尝试将UISegmentController添加到UIActionSheet中,这是我的代码

UIActionSheet *actionSheet = [[UIActionSheet alloc]initWithTitle:nil delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Copy", @"New Key", nil];

NSArray *keyLengthOptions = [NSArray arrayWithObjects:@"Option 1", @"Option 2", nil];

UISegmentedControl *segmentController = [[UISegmentedControl alloc]initWithItems:keyLengthOptions];

segmentController.frame = CGRectMake(35, 0, 250, 38);

    [segmentController addTarget:self action:@selector(segmentValueChanged:) forControlEvents:UIControlEventValueChanged];

[segmentController setSegmentedControlStyle:UISegmentedControlStyleBar];

[actionSheet addSubview:segmentController];

[actionSheet setFrame:CGRectMake(0, 0, 320, 500)];

[actionSheet showInView:self.navigationController.tabBarController.view];


一切正常,但[actionSheet setFrame:CGRectMake(0, 0, 320, 500)];无效。如何增加UIActionSheet的大小以通过子视图进行调整?

最佳答案

顺序很重要。您需要先在UIActionsheet上调用showInView :,然后调整其大小。这是另一个解决此问题的问题:

adding view into action sheet

10-04 11:56