iPhoneと入力、キーボード関連の属性
4603 ワード
テキストが入力されると、テキストボックスには次のように選択されます.
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
また、キーボードのタイプによっては、クイック入力をサポートすることもできます.
textField.keyboardType = UIKeyboardTypeAlphabet;
キーボードの表示スタイル:
textField..keyboardAppearance = UIKeyboardAppearanceAlert;
キーボードによる入力文字の制御:
textField.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
キーボードによる入力文字の自動修正
textField.autocorrectionType = UITextAutocorrectionTypeYes;
確認キーの種類
textField.returnKeyType = UIReturnKeyDone;
最後のテクニックは、ネット上の収集、キーボードの透明性、ボタンの追加の応用でもあります.
[[NSNotificationCenter defaultCenter] addObserver:self
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
typedef enum {
UITextFieldViewModeNever, //clear button
UITextFieldViewModeWhileEditing, //
UITextFieldViewModeUnlessEditing, //
UITextFieldViewModeAlways //
} UITextFieldViewMode;
また、キーボードのタイプによっては、クイック入力をサポートすることもできます.
textField.keyboardType = UIKeyboardTypeAlphabet;
typedef enum {
UIKeyboardTypeDefault, // Default type for the current input method.
UIKeyboardTypeASCIICapable, // Displays a keyboard which can enter ASCII characters, non-ASCII keyboards remain active
UIKeyboardTypeNumbersAndPunctuation, // Numbers and assorted punctuation.
UIKeyboardTypeURL, // A type optimized for URL entry (shows . / .com prominently).
UIKeyboardTypeNumberPad, // A number pad (0-9). Suitable for PIN entry.
UIKeyboardTypePhonePad, // A phone pad (1-9, *, 0, #, with letters under the numbers).
UIKeyboardTypeNamePhonePad, // A type optimized for entering a person's name or phone number.
UIKeyboardTypeEmailAddress, // A type optimized for multiple email address entry (shows space @ . prominently).
UIKeyboardTypeAlphabet = UIKeyboardTypeASCIICapable, // Deprecated
} UIKeyboardType;
キーボードの表示スタイル:
textField..keyboardAppearance = UIKeyboardAppearanceAlert;
typedef enum {
UIKeyboardAppearanceDefault, // Default apperance for the current input method.
UIKeyboardAppearanceAlert, // Appearance suitable for use in "alert" scenarios.
} UIKeyboardAppearance;
キーボードによる入力文字の制御:
textField.autocapitalizationType = UITextAutocapitalizationTypeAllCharacters;
typedef enum {
UITextAutocapitalizationTypeNone, //
UITextAutocapitalizationTypeWords, //
UITextAutocapitalizationTypeSentences, //
UITextAutocapitalizationTypeAllCharacters, //
} UITextAutocapitalizationType;
キーボードによる入力文字の自動修正
textField.autocorrectionType = UITextAutocorrectionTypeYes;
typedef enum {
UITextAutocorrectionTypeDefault,
UITextAutocorrectionTypeNo,
UITextAutocorrectionTypeYes,
} UITextAutocorrectionType;
確認キーの種類
textField.returnKeyType = UIReturnKeyDone;
typedef enum {
UIReturnKeyDefault,
UIReturnKeyGo,
UIReturnKeyGoogle,
UIReturnKeyJoin,
UIReturnKeyNext,
UIReturnKeyRoute,
UIReturnKeySearch,
UIReturnKeySend,
UIReturnKeyYahoo,
UIReturnKeyDone,
UIReturnKeyEmergencyCall,
} UIReturnKeyType;
最後のテクニックは、ネット上の収集、キーボードの透明性、ボタンの追加の応用でもあります.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(keyboardWillShow:)
name:UIKeyboardWillShowNotification
object:nil];
--------------------
- (void)keyboardWillShow:(NSNotification *)note {
// create custom button
UIButton *doneButton = [UIButton buttonWithType:UIButtonTypeCustom];
doneButton.frame = CGRectMake(0, 163, 106, 53);
doneButton.adjustsImageWhenHighlighted = NO;
[doneButton setImage:[UIImage imageNamed:@"DoneUp.png"] forState:UIControlStateNormal];
[doneButton setImage:[UIImage imageNamed:@"DoneDown.png"] forState:UIControlStateHighlighted];
[doneButton addTarget:self action:@selector(doneButton:) forControlEvents:UIControlEventTouchUpInside];
// locate keyboard view
UIWindow* tempWindow = [[[UIApplication sharedApplication] windows] objectAtIndex:1];
UIView* keyboard;
for(int i=0; i<[tempWindow.subviews count]; i++) {
keyboard = [tempWindow.subviews objectAtIndex:i];
// keyboard view found; add the custom button to it
if([[keyboard description] hasPrefix:@"<UIKeyboard"] == YES)
[keyboard addSubview:doneButton];
}
}