0

我正在创建一个应用程序,我需要在 UIAlertView 中为用户登录创建两个 UITextField 或 TextBox 用于用户 ID 和密码。我尝试了一些方法,但在这里创建的文本字段变得非常大,几乎覆盖了整个警报视图。请有人帮助我如何在警报视图中组织文本字段和标签等。我需要喜欢 - 标签“用户 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];
4

2 回答 2

1

从 iOS5 开始,UIAlertView 支持使用警报样式 UIAlertViewStyleLoginAndPasswordInput 的登录屏幕。

UIAlertView 类参考中的更多信息

于 2012-08-17T10:06:54.967 回答
0
 UIAlertView *alert =[UIAlertView alloc] init];
 alert.delegate =self //make sure to add the UIAertViewDelegate in the .h file
 alert.alertViewStyle =UIAlertViewStyleLoginAndPasswordInput;
 alert.message =@"Please login";
 [alert show];
 [alert release];

然后在 clickedButtonAtIndex 委托方法中:

{
   UITextField *username = [alertView textFieldAtIndex:0];
   UITextfield *password = [alertView textFieldAtIndex:1];
   NSLog(@"Username %"@  password %"@,username.text, password.text);
}  
于 2012-08-17T10:58:35.457 回答