Misha
Misha

Reputation: 5380

How to change UISearchBar width

I added UISearchBar to view using interface builder. Than i changed its width to be smaller using UI builder too and put it in the middle of the view. When i start application, my search bar looks correctly with width and location i defined. However after the first touch inside of it, it gets to its normal state with default width. Only its start position stays like it was defined so that it ends after the bounds of the screen.

I guess i have to subclass it and maybe override some drawRect method but i have no idea how to do it and i could not find solution to this in the net.

Upvotes: 2

Views: 1973

Answers (2)

Mohamed Hashem
Mohamed Hashem

Reputation: 156

Same problem happened to me, and I found that it was the container view that holds the UISearchBar should have the width that i need

Upvotes: 0

Try with this code

searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 10, 44)];

Upvotes: 1

Related Questions