0

I want to change the width of the textfield that is inside UISearchBar keeping its appearance.

I've tried to subclass UISearchBar and in drawRect check the self.subviews that is a kind of class UITextField and change its width, but didn't work.

I also tried this inside the layoutSubviews method but keep not working.

My objective is to have a UIButton over the right side of UISearchBar, but when I'm writing text, it can't be overlap by the UIButton.

bn.
  • 7,739
  • 7
  • 39
  • 54
David Beleza
  • 93
  • 1
  • 9

2 Answers2

1

If you really want to use UISearchBar, try the following steps:
1. Set UISearchBar's userInteractionEnabled property to NO
2. Add a UITextField above the search bar
3. Set search bar's text property when the content of UITextField is changed.

It is not a good idea to change the textfield inside the search bar, because when a new version ios comes, the struct of UISearchBar maybe changed and your code may be wrong.

Rufus
  • 640
  • 1
  • 7
  • 14
0

simply create custom search Bar using UItextField and set all properties that you want. I was did it same way, even I was tried same that you did but it didn't work.event UItextField having various event so you can implement your search functionality based on that event.