xcode 如何在 swift 语言的键盘中设置完成键?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24180263/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 05:03:54  来源:igfitidea点击:

How to set Done key in keyboard in swift-language?

iosxcodeswift

提问by Ivan R

In objective-C I use this code for adding Done key to keyboard

在 Objective-C 中,我使用此代码将 Done 键添加到键盘

[textField setReturnKeyType:UIReturnKeyDone];

How to set Done key in keyboard in swift-language?

如何在 swift 语言的键盘中设置完成键?

in swift this code gives error 'not have a member named setReturnKeyType'

在 swift 中,此代码给出错误“没有名为 setReturnKeyType 的成员”

textField.setReturnKeyType

回答by Mick MacCallum

You directly assign the value to the returnKeyType property.

您直接将值分配给 returnKeyType 属性。

textField.returnKeyType = UIReturnKeyType.Done

In Swift, you access the individual items in the enum with a dot syntax. This can also be shortened further to:

在 Swift 中,您可以使用点语法访问枚举中的各个项目。这也可以进一步缩短为:

textField.returnKeyType = .Done

回答by Prine

You can do it like that:

你可以这样做:

textField.returnKeyType = UIReturnKeyType.Done

回答by Miladinho

None Code based approach:

无 基于代码的方法:

Select your text field view from the main storyboard view controller in which it is embedded in. If you look on the Utilities view, under it's Attributes Inspector, there will be a long list of attributes. Under the Text Field heading you will se various settings such as font, alignment, placeholder etc. As you look down from there, you will come up on 6 drop down lists, titled "capitalization" through "Return Key". When you click on the list titled "return Key", you will see a list of return keys including "Search", "Yahoo","Route" etc. From this list select the "Done" keyword. That should do the trick Image of what this looks like in XCode

从嵌入它的主故事板视图控制器中选择您的文本字段视图。如果您查看 Utilities 视图,在它的 Attributes Inspector 下,将会有很长的属性列表。在文本字段标题下,您将看到各种设置,例如字体、对齐方式、占位符等。从那里往下看,您会看到 6 个下拉列表,标题为“大写”到“返回键”。当您单击标题为“返回键”的列表时,您将看到一个返回键列表,包括“搜索”、“雅虎”、“路由”等。从该列表中选择“完成”关键字。这应该可以解决这个问题 在 XCode 中看起来像什么的图像

Also From apple documentation:

也来自苹果文档

"You configure the attributes of the keyboard directly through the text objects of your app. The UITextField and UITextView classes both conform to the UITextInputTraits protocol, which defines the properties for configuring the keyboard. Setting these properties programmatically or in the Interface Builder inspector window causes the system to display the keyboard of the designated type."

“您可以通过应用程序的文本对象直接配置键盘的属性。UITextField 和 UITextView 类都符合 UITextInputTraits 协议,该协议定义了用于配置键盘的属性。以编程方式或在 Interface Builder 检查器窗口中设置这些属性会导致系统显示指定类型的键盘。”