开发者

Adding a UISegmentedControl to UISearchBar instead of Scope Buttons

开发者 https://www.devze.com 2023-03-11 09:14 出处:网络
I\'d like to add scope buttons below my UISearchBar. However I cannot change the tint color of the built in scope buttons.

I'd like to add scope buttons below my UISearchBar. However I cannot change the tint color of the built in scope buttons.

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

When I enter text into the UISearchBar, the table and segmented controls become hidden by t开发者_运维百科he "no results shown" semi-opaque black layer. Once results start showing my segmented control disappears altogether, and only cells with results show.

I want to make the segmented control clickable during text entry into the search bar.

Do you know of any way to do the following?

  1. make UISegmentedControl move with UISearchBar when text is being entered, or
  2. show UISegmentedControl whilst search results are displayed on the UITableView

Thank you


try

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

  return nil;
}

@end

to get hold of the segmented control you want, and tint it from there (it's currently at index 0, but that's definitely not for sure)

there is no "private API" being used, so apple should be okay with it, but note if they changed their view layout (unlikely), this could break, which would have the side effect of your tint disappearing, you should access the rest of its state through the standard search bar APIs

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号