How to change the alignment of a UISearchBar accor

2019-03-30 13:15发布

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.

2条回答
【Aperson】
2楼-- · 2019-03-30 13:30

Use this code in ViewDidLoad

    searchbar.semanticContentAttribute = .forceRightToLeft
查看更多
成全新的幸福
3楼-- · 2019-03-30 13:50

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

查看更多
登录 后发表回答