1

I set a default background image for UISearchBar:

[[UISearchBar appearance]setSearchFieldBackgroundImage:[UIImage imageNamed:@"search_field"] forState:UIControlStateNormal];  

I then have a UISearchBar set to the nav bar's titleView.

UIView *searchView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 200, 35)];
lsearchBar = [[TestSearchBar alloc]initWithFrame:searchView.frame];
[searchView setBackgroundColor:[UIColor clearColor]];
[searchView addSubview:lsearchBar];  

But the result looks horrible with a crushed graphic for my search bar:

If it try to embed it without using UIView directly, like this:

lessonsSearchBar = [[TestSearchBar alloc] initWithFrame:CGRectMake(0, 0, 200, 35)];
self.navigationItem.titleView = lessonsSearchBar;

it looks better, but when I push segue to the next view controller, or do pop back with animation it tries to animate it and looks horrible with this gray bar around it:

I do try it inside UIView because I also want to set a custom size to my UISearchBar and realign it a bit to the left side of the screen, which for some reason is not allowed when I set my search bar directly to navitationItem.titleView. I'm not sure exactly how to achieve this without crashing my image (which I set with setSearchFieldBackgroundImage) or without those glitches with animation. Can you please help?

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
Evgeny
  • 149
  • 1
  • 8

0 Answers0