Iphone 如何在UIAlertView中设置用户id和密码的uitextfield?

Iphone 如何在UIAlertView中设置用户id和密码的uitextfield?,iphone,objective-c,Iphone,Objective C,我正在创建一个应用程序,其中我需要在UIAlertView中创建两个UITextField或TextBox用于用户登录的用户id和密码。我尝试了一些方法,但这里创建的textfield变得非常大,几乎覆盖了整个警报视图。请有人帮助我如何在警报视图中组织textfield和标签等。我需要像-应该有一个小的文本字段对标签“用户Id”和“密码”。那怎么做呢?请帮帮我。提前准备好 UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"User

我正在创建一个应用程序,其中我需要在UIAlertView中创建两个UITextField或TextBox用于用户登录的用户id和密码。我尝试了一些方法,但这里创建的textfield变得非常大,几乎覆盖了整个警报视图。请有人帮助我如何在警报视图中组织textfield和标签等。我需要像-应该有一个小的文本字段对标签“用户Id”和“密码”。那怎么做呢?请帮帮我。提前准备好

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"User Login" message:@"Please Enter the Following \n\n\n\n\n\n\n" delegate:self cancelButtonTitle:@"Close" otherButtonTitles:@"Sign In", nil];


UILabel *lblUserName = [[UILabel alloc] initWithFrame:CGRectMake(20, 70, 85, 21)];
lblUserName.tag =2;
//lblUserName.backgroundColor = [UIColor darkGrayColor];
lblUserName.font = [UIFont systemFontOfSize:15.0];
lblUserName.text = @"User Name:";
lblUserName.textColor=[UIColor whiteColor]; 

//[lblUserName setFont:[UIFont fontWithName:@"TimesNewRomanPS-boldMT" size:8]];
lblUserName.backgroundColor = [UIColor clearColor]; 
[alert addSubview:lblUserName];

UITextField *txtUserName;

//if(txtUserName==nil)
 txtUserName = [[UITextField alloc] initWithFrame:CGRectMake(89, 50, 160, 30)];

txtUserName.tag = 3;
txtUserName.borderStyle = UITextBorderStyleBezel;
txtUserName.textColor = [UIColor whiteColor];
txtUserName.font = [UIFont systemFontOfSize:12.0];
txtUserName.placeholder = @"User ID";
[alert addSubview:txtUserName]; 



alert.tag=3;
[alert show];
[alert release];

从iOS5开始,UIAlertView支持使用警报样式UIAlertViewStyleLogin和PasswordInput的登录屏幕

更多信息请参阅

然后在ClickedButtonIndex委托方法中:

{
   UITextField *username = [alertView textFieldAtIndex:0];
   UITextfield *password = [alertView textFieldAtIndex:1];
   NSLog(@"Username %"@  password %"@,username.text, password.text);
}  
{
   UITextField *username = [alertView textFieldAtIndex:0];
   UITextfield *password = [alertView textFieldAtIndex:1];
   NSLog(@"Username %"@  password %"@,username.text, password.text);
}