自定义/更改UISearchController搜索栏,背景和范围栏的颜色

时间:2015-10-01 05:45:42

标签: ios ios8 uisearchbar uisearchcontroller

我想更改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 个答案:

答案 0 :(得分:1)

  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. 示波器条的边框颜色和示波器条内部的颜色请参见第一个答案,因为我们不了解您的意思。

相关问题