IOS 关于Text Field设置键盘

来源:互联网 发布:高丝 艾文莉 知乎 编辑:程序博客网 时间:2024/06/05 15:14

设置数字键盘 : Keyboard Type 选Number Pad

输入显示安全文本 :勾选Secure Text Entry


触摸背景隐藏软键盘

在storyboard或nib,将背景View的Custom Class设置为UIControl,这样才会有Touch事件。

右键背景View,就会出现control栏,建立事件处理方法。

- (IBAction)ViewTouchDown:(id)sender {    [[UIApplication sharedApplication] sendAction:@selector(resignFirstResponder) to:nil from:nil forEvent:nil];}


点击Return隐藏自身软键盘

右键UITextField 建立Did End on Exit事件处理方法

- (IBAction)TextFieldDidEndOnExit:(id)sender {    [sender resignFirstResponder];}



点击Return自动转到下个文本框

先有两个TextField 和button,可以把用户名TextField Return Key 设置成Next,把密码TextField Return Key 设置成Done

先用户名点击Next,焦点跳到密码框中

- (IBAction)nameTextFieldDidEndOnExit:(id)sender {    [self.passwordTF becomeFirstResponder];}
密码框点击Done,隐藏键盘同时触发btu_login按钮按下。

- (IBAction)passwordTextFieldDidEndOnExit:(id)sender {    [sender resignFirstResponder];    [btu_login sendActionsForControlEvents:UIControlEventTouchUpInside];}

强制使用系统自带键盘

- (BOOL)application:(UIApplication *)application shouldAllowExtensionPointIdentifier:(NSString *)extensionPointIdentifier{    if ([extensionPointIdentifier isEqualToString:@"com.apple.keyboard-service"]) {        return NO;    }    return YES;}




0 0
原创粉丝点击