2

It's easy to change background color of a searchbar.But, I have no idea how to change its background image.There is no direct method. I need help............... I appreciate any given idea...

Swastik
  • 2,415
  • 2
  • 31
  • 61
dev.yefeng
  • 51
  • 3
  • 5
  • 1
    possible duplicate of [UISearchBar clear background color or set background image \[iphone sdk\]](http://stackoverflow.com/questions/2139115/uisearchbar-clear-background-color-or-set-background-image-iphone-sdk) – Max Mar 08 '11 at 07:21

3 Answers3

11
UISearchBar* bar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)];
UIImageView* iview = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"test.png"]];
iview.frame = CGRectMake(0, 0, 320, 44);
[bar insertSubview:iview atIndex:1];
[iview release];
[self.view addSubview:bar];
[bar release];
hennes
  • 9,147
  • 4
  • 43
  • 63
bonny
  • 111
  • 2
3
searchBar.backgroundImage = [UIImage imageNamed:@"searchBackground"];
galmi
  • 39
  • 1
  • 2
2

if you want to use an image as the background of the search bar, you can use,

searchBar.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"search_bg.png"]];
vishiphone
  • 750
  • 7
  • 14
Nithin
  • 6,435
  • 5
  • 43
  • 56