iOS_输入text处理 和 键盘Type

<UITextFieldDelegate>

#pragma mark - UITextFieldDelegate
#pragma mark - 将要改变text时调用
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string {
  if ([string isEqualToString:@"\n"]) { // 回车收起键盘
    [textField resignFirstResponder];
    return NO;
  }
  // 判断输入的是否是数字
  NSString *regex = @"[0-9]*";
  NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex];
  if ([pred evaluateWithObject:string]) {
    // doing something
    return YES;
  }
  return NO;
}

一. keyboardType: 键盘类型

 

1.UIKeyboardTypeDefault // 默认键盘, 支持所有字符

 

 

2.UIKeyboardTypeASCIICapable     // 显示可以输入ASCII字符的键盘。

3.UIKeyboardTypeNumbersAndPunctuation     // 数字和各种标点符号

 

4.UIKeyboardTypeURL    // URL键盘, 有.com按钮, 只支持URL字符

5.UIKeyboardTypeNumberPad    // 数字键盘

6.UIKeyboardTypePhonePad    // 电话键盘
 

7.UIKeyboardTypeNamePhonePad     // 电话键盘, 也支持输入人名

8.UIKeyboardTypeEmailAddress      // 用于输入电子邮件地址的键盘

9.UIKeyboardTypeDecimalPad    IOS(4_1) // 带小数点的数字板。

10.UIKeyboardTypeTwitter    IOS(5_0) // 为twitter文本条目优化的类型(易于访问@ #)

11.UIKeyboardTypeWebSearch     IOS(7_0)    // 带有面向url的默认键盘类型。(空格很明显)。

12.UIKeyboardTypeASCIICapableNumberPad    IOS(10_0)  // 一个数字板(0-9),总是ASCII数字。

 

二. keyboardAppearance: 键盘外观颜色

typedef NS_ENUM(NSInteger, UIKeyboardAppearance) {
  UIKeyboardAppearanceDefault,          // 默认灰色.
  UIKeyboardAppearanceDark NS_ENUM_AVAILABLE_IOS(7_0),  // 深灰色
  UIKeyboardAppearanceLight NS_ENUM_AVAILABLE_IOS(7_0), // 同UIKeyboardAppearanceDefault
  UIKeyboardAppearanceAlert = UIKeyboardAppearanceDark,  // Deprecated
};

 

三. returnKeyType: return按钮类型

typedef NS_ENUM(NSInteger, UIReturnKeyType) {
  UIReturnKeyDefault, //默认:灰色按钮,标有Return
  UIReturnKeyGo,  // Go的蓝色按钮
  UIReturnKeyGoogle,  // Google的蓝色按钮,用于搜索
  UIReturnKeyJoin,  // Join的蓝色按钮
  UIReturnKeyNext,  // Next的蓝色按钮
  UIReturnKeyRoute, // Route的蓝色按钮
  UIReturnKeySearch,  // Search的蓝色按钮
  UIReturnKeySend,  // Send的蓝色按钮
  UIReturnKeyYahoo, // Yahoo!的蓝色按钮,用于搜索
  UIReturnKeyDone,  // Done的蓝色按钮
  UIReturnKeyEmergencyCall, // EmergencyCall的蓝色 (紧急呼叫) 按钮
  UIReturnKeyContinue NS_ENUM_AVAILABLE_IOS(9_0), // //标有Done的灰色按钮
};

 

四. autocapitalizationType: 大小写设置

typedef NS_ENUM(NSInteger, UITextAutocapitalizationType) {
  UITextAutocapitalizationTypeNone, // 不自动大写
  UITextAutocapitalizationTypeWords,  // 单词首字母大写
  UITextAutocapitalizationTypeSentences,  // 句子首字母大写
  UITextAutocapitalizationTypeAllCharacters,  // 所有字母大写
};

 

五. autocorrectionType: 自动更正

typedef NS_ENUM(NSInteger, UITextAutocorrectionType) {
  UITextAutocorrectionTypeDefault,
  UITextAutocorrectionTypeNo,   // 不自动更正
  UITextAutocorrectionTypeYes,  // 自动更正
};

 

六. secureTextEntry: 安全输入 YES or NO

 

七. enablesReturnKeyAutomatically 换行自动检测是否允许 

// 默认NO YES时:text为空return按钮 disenable(禁用)

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章