试试这个代码
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Enter Student Name"
message:@""
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Save",@"Save & Add",nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
-(void)willPresentAlertView:(UIAlertView *)alertView {
if ([[[UIDevice currentDevice] systemVersion] floatValue] <7)
{
[alertView setFrame:CGRectMake(17, 30, 286, 280)];
NSArray *subviewArray = [alertView subviews];
UILabel *message = (UILabel *)[subviewArray objectAtIndex:2];
[message setFrame:CGRectMake(10, 46, 260, 20)];
UIButton *cancelbutton = (UIButton *)[subviewArray objectAtIndex:3];
[cancelbutton setFrame:CGRectMake(10, 125, 260, 42)];
UIButton *savebutton = (UIButton *)[subviewArray objectAtIndex:4];
[savebutton setFrame:CGRectMake(10, 170, 260, 42)];
UIButton *saveAddbutton = (UIButton *)[subviewArray objectAtIndex:5];
[saveAddbutton setFrame:CGRectMake(10, 220, 260, 42)];
UITextField *textfield = (UITextField *)[subviewArray objectAtIndex:6];
[textfield setFrame:CGRectMake(10, 80, 266, 50)];
UITextField *placeTF = (UITextField *)[subviewArray objectAtIndex:7];
[placeTF setFrame:CGRectMake(15, 70, 256, 50)];
}
}
检查 ios 6 映像
编辑
对于旋转问题,请使用此代码
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
if (UIInterfaceOrientationPortrait == UIInterfaceOrientationIsPortrait(fromInterfaceOrientation))
{
[alert setFrame:CGRectMake(100, 10, 286, 320)];
NSArray *subviewArray = [alert subviews];
UILabel *messageLB = (UILabel *)[subviewArray objectAtIndex:2];
[messageLB setFrame:CGRectMake(10, 46, 260, 20)];
UIButton *cancelBT = (UIButton *)[subviewArray objectAtIndex:3];
[cancelBT setFrame:CGRectMake(10, 125, 260, 42)];
UIButton *okBT = (UIButton *)[subviewArray objectAtIndex:4];
[okBT setFrame:CGRectMake(10, 170, 260, 42)];
UIButton *searchBT = (UIButton *)[subviewArray objectAtIndex:5];
[searchBT setFrame:CGRectMake(10, 220, 260, 42)];
UITextField *plateTF = (UITextField *)[subviewArray objectAtIndex:6];
[plateTF setFrame:CGRectMake(10, 80, 266, 50)];
UITextField *placeTF = (UITextField *)[subviewArray objectAtIndex:7];
[placeTF setFrame:CGRectMake(15, 70, 256, 50)];
}
else{
[alert setFrame:CGRectMake(17, 30, 286, 280)];
NSArray *subviewArray = [alert subviews];
UILabel *messageLB = (UILabel *)[subviewArray objectAtIndex:2];
[messageLB setFrame:CGRectMake(10, 46, 260, 20)];
UIButton *cancelBT = (UIButton *)[subviewArray objectAtIndex:3];
[cancelBT setFrame:CGRectMake(10, 125, 260, 42)];
UIButton *okBT = (UIButton *)[subviewArray objectAtIndex:4];
[okBT setFrame:CGRectMake(10, 170, 260, 42)];
UIButton *searchBT = (UIButton *)[subviewArray objectAtIndex:5];
[searchBT setFrame:CGRectMake(10, 220, 260, 42)];
UITextField *plateTF = (UITextField *)[subviewArray objectAtIndex:6];
[plateTF setFrame:CGRectMake(10, 80, 266, 50)];
UITextField *placeTF = (UITextField *)[subviewArray objectAtIndex:7];
[placeTF setFrame:CGRectMake(15, 70, 256, 50)];
}
}