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

I would like to be able to enter text in languages ​​from left to right and from right to left in the UISearchBar. This means that after the user began to enter text in languages ​​from right to left, I would like the text to be aligned to the right and vice versa.

Question: is there a way to catch these language switching events? Thank you for your help.

+4
source share
2 answers

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

+1
source

Use this code in ViewDidLoad

    searchbar.semanticContentAttribute = .forceRightToLeft
+1
source

All Articles