What I did was I created a UISearchBar
subclass and in IB made the searchBar belonging to the UISearchDisplayController
part of that subclass. From there I was able to change the tintColor
and backgroundColor
. The reason I needed this was because the UISearchBar
was not displaying correctly within a UINavigationBar
and this was the only way I could think of on, how to do it.
Edit
Your actually able to do this relatively easy with UISearchDisplayController
's initializer, initWithSearchBar:contentsController:
, however you'll still need to subclass UISearchBar
.
Here is the Code I used. Now if your performing this through IB you only need to use initWithCoder:
but I created a setup
method. Just incase, I need to use it again, in places other than IB.
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self setup];
}
return self;
}
-(id) initWithCoder:(NSCoder *)aDecoder {
if (self = [super initWithCoder:aDecoder]) {
[self setup];
}
return self;
}
-(id)init {
if (self = [super init]) {
[self setup];
}
return self;
}
-(void) setup {
self.backgroundColor = [UIColor clearColor];
self.tintColor = [UIColor clearColor];
for (UIView * view in self.subviews) {
if ([view isMemberOfClass:NSClassFromString(@"UISearchBarBackground")]) {
view.alpha = 0.0;
}
}
}