Has anyone managed to color the scopebar portion of a UISearchBar, it has a tintColor property but setting it does not affect the attached scopebar UISegmentedControl. Ive got a
Here's some copy paste friendly code for what the others are discussing.
scopeBar.segmentedControlStyle = UISegmentedControlStyleBar; //required for color change
for (id subview in self.searchDisplayController.searchBar.subviews )
{
if([subview isMemberOfClass:[UISegmentedControl class]])
{
UISegmentedControl *scopeBar=(UISegmentedControl *) subview;
scopeBar.tintColor = [UIColor blackColor];
}
}
If you a white box like area around your buttons, you can change the color of that through interface builder.
I wouldn't say it looks "like ass" as the others do, but it isn't really ideal either.
I have not been able to get the tint set reliably for a scope bar.
What I've ended up doing is changing the search bar's tintColor
... UNTIL transitioning into search mode, at which point I make it the default color to match the scope bar. Then, when canceling the search, I change it back.
One spot that I seem to be missing here is the transition that occurs when the corresponding tableView
is tapped, causing the search bar to lose first responder status. In that case, the color does not change back. Reason: I base that color change on having the search bar's cancel button being clicked.
Knee-jerk reaction: searchBarCancelButtonClicked:
should get called (wherein we change back the tint) ... but that can't be right, because Cancel wasn't clicked. I really need a "Search is done" type of detection. Maybe just keep an eye on first responder and see when UISearchBar moves in and out of that state?