How to change the alignment of a UISearchBar according to the input language

若如初见. 提交于 2019-12-05 01:47:44

问题


I would like to be able to input text in either Left-to-Right and Right-to-Left languages into a UISearchBar. This means that once a user has started inputing text in right to left languages, I would like the text alignment to be to the right and vice versa.

The question is - Is there any way to catch these events of language switching? Thanks for your help.


回答1:


Yes there is. You want to subscribe to UITextInputCurrentInputModeDidChangeNotification. See the UITextInputMode Class Reference.




回答2:


Use this code in ViewDidLoad

    searchbar.semanticContentAttribute = .forceRightToLeft


来源:https://stackoverflow.com/questions/9251592/how-to-change-the-alignment-of-a-uisearchbar-according-to-the-input-language

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