How to install Done key on keyboard in swift-laguage?

In objective-C, I use this code to add a Done key to the keyboard

[textField setReturnKeyType:UIReturnKeyDone]; 

How to install Done key on keyboard in swift-laguage?

in swift, this code gives the error "does not have a member named setReturnKeyType"

 textField.setReturnKeyType 
+6
source share
3 answers

You directly assign a value to the returnKeyType property.

 textField.returnKeyType = UIReturnKeyType.Done 

In Swift, you get access to individual enumeration elements with dot syntax. This can also be reduced further:

 textField.returnKeyType = .Done 
+24
source

You can do it as follows:

 textField.returnKeyType = UIReturnKeyType.Done 
+3
source

There is no code based approach:

Select the type of text field from the main storyboard view controller in which it is embedded. If you look in the Utilities view, there will be a long list of attributes in Attributes Inspector. Under the heading "Text box" you will find various settings, such as font, alignment, placeholder, etc. When you look down, you will go to 6 drop-down lists called "capitalization" through the "Return Key". When you click on the list called “Return Key”, you will see a list of return keys, including “Search,” “Yahoo,” “Route,” etc. From the list, select the Done keyword. That should do the trick. Image of how it looks in Xcode

Also from apple documentation :

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

+1
source

Source: https://habr.com/ru/post/970731/


All Articles