Adding a UISegmentedControl to a UISearchBar instead of Scope buttons

I want to add area buttons under my UISearchBar. However, I cannot change the color of the shades of the built-in zoom buttons.

Instead, I added a UISegmentedControl to my tableViewHeader. This works pretty well, but it only shows when I am not typing in the UISearchbar. Not very comfortable.

When I enter text in a UISearchBar, the table and the segmented controls become hidden by the semi-opaque black “no results” layer. As soon as the results begin to show my segmented control disappears altogether, and only the cells with the results are displayed.

I want the segmented control to be clickable while typing in the search bar.

Do you know any way to do the following?

  • cause the UISegmentedControl to move with the UISearchBar when entering text or
  • show UISegmentedControl while search results are displayed in UITableView

thank

+3
source share
1 answer

to try

@implementation UISearchBar (subviewAccess)
- (UISegmentedControl *)scopeBar {
  for (UIView *v in [self subviews]) {
    if ([v isKindOfClass:[UISegmentedControl class]])
      return v;
  }

  return nil;
}

@end

to get the desired segmented control and hone it from there (it is currently at index 0, but this is definitely not necessary)

there is no “private API”, so the apple should be fine with it, but note whether they changed the layout of the view (unlikely), it may break, which will have a side effect of the fade, you should access the rest of its state through standard Search APIs

0

All Articles