ios - 如何将目标添加到键盘完成/转到/搜索按钮?

标签 ios swift keyboard action addtarget

我想给键盘上的按钮附加一个 Action 。我不想创建自定义键盘,只处理搜索/开始/完成按钮操作。

enter image description here

谢谢!

最佳答案

要处理返回键,您使用委托(delegate) textFieldShouldReturn

func textFieldShouldReturn(_ textField: UITextField) -> Bool {
         // your Action According to your textfield
        return true
    }

如何更改回车键

yourTextField.returnKeyType = UIReturnKeyType.search
yourTextField.returnKeyType = UIReturnKeyType.done

Apple 枚举:

typedef NS_ENUM(NSInteger, UIReturnKeyType) {
    UIReturnKeyDefault,
    UIReturnKeyGo,
    UIReturnKeyGoogle,
    UIReturnKeyJoin,
    UIReturnKeyNext,
    UIReturnKeyRoute,
    UIReturnKeySearch,
    UIReturnKeySend,
    UIReturnKeyYahoo,
    UIReturnKeyDone,
    UIReturnKeyEmergencyCall,
    UIReturnKeyContinue NS_ENUM_AVAILABLE_IOS(9_0),
}

关于ios - 如何将目标添加到键盘完成/转到/搜索按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50444197/

相关文章:

iphone - 当应用程序重新启动时取消由 applicationDidEnterBackground 启动的任务

ios - PhoneGap- 屏幕方向不适用于 iOS 中的照片库

swift - Realm 类名称与数据库中的存储名称不同

从 xib 转到类和从 xib 到类的 Xcode 键盘快捷键?

ios - 当键盘出现时,如何将最后一个文本字段的 View 向上移动?

iphone - 带有替换变量的 HTML 的简单 ParseKit 语法

swift - 将 UInt8(或类似类型)转换为 Int 是否违背了 UInt8 的目的?

ios - 在ios中获取Scrollview tabview标签卡住了

html - 在 Mobile Safari 中启用键盘类型 DecimalPad(通过 HTML)

ios - 有一个更好的方法吗?想使用循环,但它中断了