首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >iOS_输入text处理 和 键盘Type

iOS_输入text处理 和 键盘Type

作者头像
mikimo
发布2022-07-20 13:56:13
发布2022-07-20 13:56:13
1.5K0
举报
文章被收录于专栏:iOS开发~iOS开发~

<UITextFieldDelegate>

代码语言:javascript
复制
#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: 键盘外观颜色

代码语言:javascript
复制
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按钮类型

代码语言:javascript
复制
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: 大小写设置

代码语言:javascript
复制
typedef NS_ENUM(NSInteger, UITextAutocapitalizationType) {
  UITextAutocapitalizationTypeNone, // 不自动大写
  UITextAutocapitalizationTypeWords,  // 单词首字母大写
  UITextAutocapitalizationTypeSentences,  // 句子首字母大写
  UITextAutocapitalizationTypeAllCharacters,  // 所有字母大写
};

五. autocorrectionType: 自动更正

代码语言:javascript
复制
typedef NS_ENUM(NSInteger, UITextAutocorrectionType) {
  UITextAutocorrectionTypeDefault,
  UITextAutocorrectionTypeNo,   // 不自动更正
  UITextAutocorrectionTypeYes,  // 自动更正
};

六. secureTextEntry: 安全输入 YES or NO

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

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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2018-06-24,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档