0

I'm using UISearchDisplayControlleron UInavigationBar but the background color of UISearchDisplayController is not matching the color of uinavigationbar. i used the following code in ma ViewDidLoad but no change I'm unable to change the color of UISearchDisplayController

self.searchDisplayController.searchBar.tintColor = [UIColor clearColor];
Cœur
  • 37,241
  • 25
  • 195
  • 267
Muddu Patil
  • 713
  • 1
  • 11
  • 24

2 Answers2

0

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;
        }
    }
}
user828267
  • 303
  • 4
  • 9
0

A UISearchDisplayController is not an interface element. It is a controller, not a view. It has no color.

matt
  • 515,959
  • 87
  • 875
  • 1,141
  • I think he understands that but `UISearchDisplayController` has a `searchBar` property. Which he is using in his code example. – user828267 May 17 '13 at 15:43