user1523344
user1523344

Reputation: 123

How to put uitextfield for user id and password in UIAlertView?

I am creating an application where i need to create two UITextField or TextBox for User id and password inside a UIAlertView for User login.I have tried something but here the textfield created becomes very big and almost cover the whole alert view.Please somebody help me how to organize the textfield and labels etc inside the alert view. I need like - there should be a small textfield against the label "User Id" and "Password". So how to do that? please help me. Thanx in advance.

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];

Upvotes: 0

Views: 474

Answers (2)

glenn sayers
glenn sayers

Reputation: 2414

 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];

Then in the clickedButtonAtIndex delegate method:

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

Upvotes: 0

Asciiom
Asciiom

Reputation: 9975

As of iOS5, UIAlertView supports a login screen using the Alert Style UIAlertViewStyleLoginAndPasswordInput.

More information in the UIAlertView Class Reference

Upvotes: 1

Related Questions