Change UISearchBar/Keyboard Search Button Title in Swift

a 夏天 提交于 2019-12-23 20:28:08

问题


I'm trying to do the equivalent of this but in Swift and I'm running into problems:

  1. No equivalent of try/catch blocks in swift
  2. The if statement never seems to be evaluated as true

Here is what I've put together so far:

for searchBarSubview in self.searchBar!.subviews {
    if (searchBarSubview.conformsToProtocol(UITextInputTraits)) {
        var searchBarTextField = searchBarSubview as UITextField
        searchBarTextField.returnKeyType = UIReturnKeyType.Done
    }
}

Does anyone have any ideas where I'm going wrong?


回答1:


I think you only need to do the following code and you are good to go. Any reasons why that bothers you to check UITextInputTraits?

[self.searchBar setReturnKeyType:UIReturnKeyDone];



回答2:


To change return type of UISearchBar in swift

searchBar.returnKeyType = UIReturnKeyType.Done

Other Enum

    case Default
    case Go
    case Google
    case Join
    case Next
    case Route
    case Search
    case Send
    case Yahoo
    case Done
    case EmergencyCall
    @available(iOS 9.0, *)
    case Continue


来源:https://stackoverflow.com/questions/30415284/change-uisearchbar-keyboard-search-button-title-in-swift

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!