So I noticed a lot of people are trying to get UITextFields into UIAlertViews by manually generating one and fixing the coordinates, etc. But What a lot of people don't know is that Apple has an easier (non-documented) way that they do this, in apps like iTunes, etc.
// First Let's Make a UIAlertView Like Normal..
UIAlertView *myAlert = [[UIAlertView alloc] init];
[myAlert setTitle:@"ALERT TITLE"];
[myAlert setMessage:@"HELLO WORLD"];
[myAlert setDelegate:self];
[myAlert setTag:1];
[myAlert addTextFieldWithValue:@"" label:@"ADD LABEL HERE"];
[myAlert addButtonWithTitle:@"OK"];
[myAlert addButtonWithTitle:@"Cancel"];
// Now Let's Use Apple's Special Way of Adding a UITextField with little to no work
txtInput = [myAlert textFieldAtIndex:0];
txtInput.clearButtonMode = UITextFieldViewModeWhileEditing;
txtInput.keyboardType = UIKeyboardTypeDefault;
txtInput.keyboardAppearance = UIKeyboardAppearanceAlert;
txtInput.autocorrectionType = UITextAutocorrectionTypeNo;
txtInput.secureTextEntry = NO;
[myAlert show];
[myAlert release];
Clear Button Mode adds the little "X" while typing to clear the UITextField. Keyboardtype obviously sets the type of keyboard. Here are your options for that:
UIKeyboardTypeDefault
Use the default keyboard for the current input method.
Available in iPhone OS 2.0 and later.
Declared in UITextInputTraits.h
.
UIKeyboardTypeASCIICapable
Use a keyboard that displays standard ASCII characters.
Available in iPhone OS 2.0 and later.
Declared in UITextInputTraits.h
.
UIKeyboardTypeNumbersAndPunctuation
Use the numbers and punctuation keyboard.
Available in iPhone OS 2.0 and later.
Declared in UITextInputTraits.h
.
UIKeyboardTypeURL
Use a keyboard optimized for URL entry. This type features “.”, “/”, and “.com” prominently.
Available in iPhone OS 2.0 and later.
Declared in UITextInputTraits.h
.
UIKeyboardTypeNumberPad
Use a numeric keypad designed for PIN entry. This type features the numbers 0 through 9 prominently. This keyboard type does not support auto-capitalization.
Available in iPhone OS 2.0 and later.
Declared in UITextInputTraits.h
.
UIKeyboardTypePhonePad
Use a keypad designed for entering telephone numbers. This type features the numbers 0 through 9 and the “*” and “#” characters prominently. This keyboard type does not support auto-capitalization.
Available in iPhone OS 2.0 and later.
Declared in UITextInputTraits.h
.
UIKeyboardTypeNamePhonePad
Use a keypad designed for entering a person’s name or phone number. This keyboard type does not support auto-capitalization.
Available in iPhone OS 2.0 and later.
Declared in UITextInputTraits.h
.
UIKeyboardTypeEmailAddress
Use a keyboard optimized for specifying email addresses. This type features the “@”, “.” and space characters prominently.
Available in iPhone OS 2.0 and later.
Declared in UITextInputTraits.h
.
and Finally, secureTextEntry allows you to change the characters to dots if you are entering a password.
And of course, you can add more than one UITextField to a UIAlertView, so this should please all of your username/password needs.
~Collateral
1 comment:
This will get rejected in the appstore .
Post a Comment
You can also follow any responses to all entry through the RSS Comments feed.