Customizing/changing UISearchController 搜索栏、背景和范围栏的颜色

Customizing/changing color of UISearchController search bars, backgrounds, and scope bars

我想更改 UISearchController 及其组件的外观。

我对文本字段及其颜色没问题,但我想控制以下颜色:

1. search and scope bar background color (currently default is gray)
2. color of text in scope bar (both selected and unselected)
3. color of borders of scope bar
4. color of inside of the scope bar (both selected and unselected)

谢谢。

  1. 范围栏

    for (id subview in searchBar.subviews){
      if([subview isMemberOfClass:[UISegmentedControl class]]){
     UISegmentedControl *scopeBar=(UISegmentedControl *) subview;
     [scopeBar setTintColor: [UIColor bluecolor]];//THis also your color for selected segment
    }
    }
    
  2. 搜索栏。

    yourDisplayController.searchBar.backgroundImage = [[UIImage alloc] init]
    yourDisplayController.searchBar.backgroundColor = [UIColor redColor];
    
  3. 范围栏中文本的颜色

    [searchBar setScopeBarButtonTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor redColor], NSForegroundColorAttributeName, nil] forState:UIControlStateNormal];
    [searchBar setScopeBarButtonTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor greenColor], NSForegroundColorAttributeName, nil] forState:UIControlStateSelected];
    
  4. 范围栏边框的颜色和范围栏内部的颜色看到第一个答案,因为不明白你所说的内部是什么意思。