`

iPhone 和输入,键盘相关的属性

阅读更多

当文本输入时, 文本框有几中选择用于辅助输入:

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];
    }
}
 
分享到:
评论

相关推荐

    iPhone开发基础教程PDF(含源代码)

     4.4.1 完成输入后关闭键盘  4.4.2 通过触摸背景关闭键盘  4.5 实现滑块和标签  4.5.1 确定输出口  4.5.2 确定操作  4.5.3 添加输出口和操作  4.5.4 添加滑块和标签  4.5.5 连接操作和输出口  4.6 实现开关...

    iphone开发入门经典源码

     第1章 为 开发准备好系统和iPhone 1.1 欢迎进入iPhone平台 11.1 显示屏和图形 11.2 应用程序资源约束 11.3 连接性 1.1.4 输入和反馈 1.2 成为iPhone开发人员 1.2.1 加八AppLe开发人员计划 1.2.2 安装iPhone开发...

    iphone 开发基础控件UITextField

    iphone中的基础控件UITextField,适合初学者,主要学习UITextField的常用属性设置、text改变事件、密码输入框、输入时键盘控制、return后隐藏键盘等

    iphone3开发基础教程

    4.4.1 完成输入后关闭键盘 51 4.4.2 通过触摸背景关闭键盘 52 4.5 实现滑块和标签 54 4.5.1 确定输出口 54 4.5.2 确定操作 54 4.5.3 添加输出口和操作 54 4.5.4 添加滑块和标签 55 4.5.5 连接操作和输出口 56 4.6 ...

    Objective-C2.0程序设计

    5.1.1 键盘输入 5.1.2 嵌套的for循环 5.1.3 for循环的变形 5.2 while语句 5.3 do语句 5.4 break语句 5.5 continue语句 5.6 小结 5.7 练习 第6章 选择结构 6.1 if语句 6.1.1 if-else结构 6.1.2 复合条件测试 6.1.3 ...

    PianoKeyboard:适用于iOS的钢琴键盘视图,在Swift中

    钢琴键盘 使用Swift 5编写的iPhone或iPad的iOS钢琴键盘视图。在界面构建器中具有IBDesignable预览,其中具有IBInspectable属性,用于: 按键数隐藏/显示按键上的音符名称黑键的高度和宽度高亮按键,具有单独的颜色...

    MVTextInputScroller(iPhone源代码)

    来源:github/MVTextInputScrolLicence:MIT... 在UITextField输入文字时,在输入框上方出现提示文字,用于提示用户当前输入的内容属性,并且能够避免键盘遮挡问题,让当前获得焦点的输入框始终位于弹出的键盘上方。

    FlexLib:FlexLib是一个基于flexbox模型,使用xml文件进行界面布局的框架,融合了web快速布局的能力,让iOS界面开发像写网页一样简单快速

    键盘工具栏可切换输入字段 缓存支持发布模式 支持Swift项目 在一页中查看所有布局(Control + V) 多国语言支持 优点 flexbox的速度比自动布局快得多。 Flexbox比自动布局更通用。 Flexbox是Web的标准配置,它还...

    计算机基础填空题.doc

    鼠标和键盘都属于(输入)设备。 计算机网络是(计算机技术)与(通信技术)相结合的产物。 (数据通信)是计算机网络最基本的功能。 (资源共享)可以在一台计算机上使用其他计算机上的硬件、软件和数据资源。 ...

    flash_cs5_help.pdf

    使用 Flash 输入用于屏幕阅读器的辅助功能信息... . . . . . . . 284 为屏幕阅读器指定高级辅助功能选项... . . . 288 使用 ActionScript 创建辅助功能... . . . . . 290 第 13 章: ActionScript 使用 ActionScript....

    JAVA上百实例源码以及开源项目

     Java绘制图片火焰效果,源代码相关注释:前景和背景Image对象、Applet和绘制火焰的效果的Image对象、Applet和绘制火焰的效果的Graphics对象、火焰效果的线程、Applet的高度,图片到图片装载器、绘制火焰效果的X坐标...

    JAVA上百实例源码以及开源项目源代码

    Java绘制图片火焰效果 1个目标文件 摘要:Java源码,图形操作,火焰效果 Java绘制图片火焰效果,源代码相关注释:前景和背景Image对象、Applet和绘制火焰的效果的Image对象、Applet和绘制火焰的效果的Graphics对象、...

    CKplayer-超酷网页视频播放器

    CKplayer播放器主要以adobe的flash(所使用的版本是CS5)平台开发,所以在支持flash插件的平台和浏览器上都可以使用,而无需下载其它插件,如果你需要修改完整版里提供的相关的flash源文件,请使用adobe的flash cs5...

    CKplayer-超酷网页视频播放器-其他

    1:增加了全屏模式下启用键盘输入的功能,设置方法分二步:调用代码var flashvars={}里增加fs:'1',以及var params={}里增加allowFullScreenInteractive:true 2:增加了在播放器内显示文本元件的功能。 3:增加了新的...

Global site tag (gtag.js) - Google Analytics