"Alert (UIAlertView) with text field (UITextField)"

Mon 11 May 2009

// open a alert with text field,  OK and cancel button

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Send Email" message:@" "

       delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Send", nil];

 

CGRect frame = CGRectMake(14, 45, 255, 23);

if(!emailField) {

emailField = [[UITextField alloc] initWithFrame:frame];

emailField.borderStyle = UITextBorderStyleBezel;

emailField.textColor = [UIColor blackColor];

emailField.textAlignment = UITextAlignmentCenter;

emailField.font = [UIFont systemFontOfSize:14.0];

emailField.placeholder = @"<enter email>";


emailField.backgroundColor = [UIColor whiteColor];

emailField.autocorrectionType = UITextAutocorrectionTypeNo; // no auto correction support

emailField.keyboardType = UIKeyboardTypeEmailAddress; // use the default type input method (entire keyboard)

emailField.returnKeyType = UIReturnKeyDone;

emailField.delegate = self;

emailField.clearButtonMode = UITextFieldViewModeWhileEditing; // has a clear 'x' button to the right

}

 

[alert addSubview:emailField];

 

[alert show];

[alert release];