On iOS 7 UISearchBar left align placeholder text?

后端 未结 2 1021
暖寄归人
暖寄归人 2021-02-19 07:20

On iOS 7 UISearchBar the placeholder text is centred and I want to disable that and make it always stick to the left like it was before.

2条回答
  •  难免孤独
    2021-02-19 07:48

    To get left alignment of the placeholder in iOS7 you can add white spaces to the end of your placeholder string. For example:

    _searchBar.placeholder = @"Search                  ";
    

    Note that it is should be done separately for each search bar and each language.

    One could try to write automatic calculation of needed spaces after text for any language but it seems impossible to read the size of searchBar's textField frame

提交回复
热议问题