【问题标题】:How to put uitextfield for user id and password in UIAlertView?如何在 UIAlertView 中放置用户 ID 和密码的 uitextfield?
【发布时间】:2012-08-17 10:05:01
【问题描述】:

我正在创建一个应用程序,我需要在 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];

【问题讨论】:

    标签: iphone objective-c


    【解决方案1】:

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

    更多信息在UIAlertView Class Reference

    【讨论】:

      【解决方案2】:
       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);
      }  
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多