Reputation: 499
I want to wait for a username input by alert dialog, how to add UITextField on UIAlertView
Upvotes: 2
Views: 6493
Reputation: 150615
This has changed since iOS5. You can now create a UIAlertView with a style.
UIAlertView now has a property - alertViewStyle
that you can set to one of the enum values
Once you've created the alert view, you set it style and display it. After dismissing the alert, you can access the contents of the fields using the textFieldAtIndex:
property of the alert view.
Upvotes: 8
Reputation: 4517
Like this :
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Twitter Login" message:@"\n\n\n" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Sign In", nil];
myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
myTextField.placeholder=@"Enter User Name";
[myTextField becomeFirstResponder];
[myTextField setBackgroundColor:[UIColor whiteColor]];
myTextField.textAlignment=UITextAlignmentCenter;
// myTextField.layer.cornerRadius=5.0; Use this if you have added QuartzCore framework
[myAlertView addSubview:myTextField];
[myAlertView show];
[myAlertView release];
Upvotes: 6
Reputation: 4517
Like this:
UIAlertView *myAlertView = [[UIAlertView alloc] initWithTitle:@"Twitter Login" message:@"\n\n\n" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Sign In", nil];
myTextField = [[UITextField alloc] initWithFrame:CGRectMake(12.0, 45.0, 260.0, 25.0)];
myTextField.placeholder=@"Enter User Name";
[myTextField becomeFirstResponder];
[myTextField setBackgroundColor:[UIColor whiteColor]];
myTextField.textAlignment=UITextAlignmentCenter;
// myTextField.layer.cornerRadius=5.0; Use this if you have added QuartzCore framework
[myAlertView addSubview:myTextField];
[myAlertView show];
[myAlertView release];
Hope this will solve your problem.......
Upvotes: 0