On iOS 7 UISearchBar left align placeholder text?

后端 未结 2 1024
暖寄归人
暖寄归人 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:46

    I haven't tried it with a UISearchBar but this works with a UITextField. I Subclassed it and overrode leftViewRectForBounds:, textRectForBounds: and editingRectForBounds:, here is the code:

    - (CGRect)textRectForBounds:(CGRect)bounds {
      CGRect inset = CGRectMake(bounds.origin.x + kLeftTextPadding,
                            bounds.origin.y,
                            bounds.size.width - kLeftTextPadding,
                            bounds.size.height);
      return inset;
    }
    

    Hope it helps.

提交回复
热议问题