When I set a search field background image on a UIImage
, the padding between the magnifying glass and placeholder text in the search bar when selected changes.
With the default background:
With a custom background:
This change is caused by these two lines:
UIImage *colorImage = [UIImage imageWithColor:[UIColor grayColor] size:CGSizeMake(28, 28)];
[self setSearchFieldBackgroundImage:[colorImage imageWithRoundedCorners:5] forState:UIControlStateNormal];
imageWithRoundedCorners:
is a category method that simply draws the image onto a CALayer
with a corner radius and then creates a UIImage
from the graphics context.
Why is this and how can I avoid this? I tried passing an explicitly resizable image, but that had no effect.
Its odd that it resets it, however you can use something like this to set it to your liking after setting the background image.
searchTextPositionAdjustment
is a property on UISearchBar and works perfectly. 8.0 seems to be the default, but you could set it to whatever you like.