5

How do I remove the shine/glow (gradient) from the background of a Search Bar. I would like to replace it with just one color.

From this:

enter image description here

To something like this

enter image description here

Mohsen Safari
  • 6,669
  • 5
  • 42
  • 58
Nikolaj
  • 53
  • 1
  • 4

3 Answers3

1

Use

searchbar.backgroundImage = //your image here

and you can use a nifty category that I created for uiimage that will generate an image based on a color

https://github.com/Hackmodford/HMUIImage-imageWithColor

So all together it will look like this

searchBar.backgroundImage = [UIImage imageWithColor:[UIColor blueColor]];

That will generate the effect you want.

Hackmodford
  • 3,901
  • 4
  • 35
  • 78
1

1 To remove the glossy background:

UISearchBar has a subview of class UISearchBarBackground, just cycle through the subviews and when you find a subview of that class, set its alpha to 0.

RubyMotion example:

searchBar.subviews.each { |v| v.alpha = 0 if v.class == UISearchBarBackground }  

2 To add a solid background override the drawRect method:

RubyMotion example:

def drawRect(rect)
  blackColor = '#222222'.to_color
  context = UIGraphicsGetCurrentContext()
  CGContextSetFillColor(context, CGColorGetComponents(blackColor.CGColor))
  CGContextFillRect(context, rect)      
end
defvol
  • 14,392
  • 2
  • 22
  • 32
0

Dont think you can, tried it myself and it seems to be part of the API, heres a similar post that asks the same thing The reason the FB one is a solid colour is because afaik the FB app use the Three20 framework. But even with all their scaling down its still a raw 30 megs in size, extreme overkill for a search bar in your case

Dont even know if an image will work as you can't set the area around the bar itself to be clear or transparent to put an image under it

Community
  • 1
  • 1
Elmo
  • 407
  • 4
  • 15
  • But the facebook application is only like 6MB in size? – Nikolaj Jul 16 '11 at 12:12
  • When you convert your app for uploading to the store it'll shrink a lot. An app i was working on for a company was several hundred megs due to Three20 and a load of images, to download it's about 8mbs – Elmo Jul 16 '11 at 16:47