you have to use adding subView in alertView's delegate method because alertView calculates its frame before showing to user.
UIAlertView *alertView=[[UIAlertView alloc] initWithTitle:@"Hello SubViews" message:nil delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alertView show];
- (void)willPresentAlertView:(UIAlertView *)alertView
{
CGFloat height = 25.0;
UILabel *firstLabel = (UILabel*)[[alertView subviews] objectAtIndex:1];
CGRect label_rect=firstLabel.frame;
UISegmentedControl *segment=[[UISegmentedControl alloc] initWithItems:[NSArray arrayWithObjects:@"Me",@"And",@"You",nil]];
segment.segmentedControlStyle=UISegmentedControlStyleBar;
[segment setFrame:CGRectMake(label_rect.origin.x, label_rect.origin.y+label_rect.size.height,label_rect.size.width,height)];
UITextField *textField = [[UITextField alloc] initWithFrame:CGRectOffset(segment.frame, 0, height + 4)];
[textField setText:@"Enter some text"];
[textField setBackgroundColor:[UIColor whiteColor]];
UIButton *okBtn=(UIButton*)[[alertView subviews] objectAtIndex:2];
[okBtn setFrame:CGRectOffset(textField.frame, 0, height + 4)];
[alertView addSubview:segment];
[alertView addSubview:textField];
alertView.frame = CGRectUnion(alertView.frame, CGRectOffset(alertView.frame, 0, 40));
}
出力 - - - - - - - -
