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

标签 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. 对于范围栏

    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. 范围栏边框的颜色和范围栏内部的颜色看到第一个答案,因为不明白你所说的内部是什么意思。

关于ios - 自定义/更改 UISearchController 搜索栏、背景和范围栏的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32880233/

相关文章:

ios - 在导航 Controller 中推送 Controller 时如何隐藏父标签栏

ios - 使用 NSUserDefaults 或 CoreData 存储事件日历

ios - 检测设备是否正确显示 UIVisualEffectView?

iphone - 如何通过代码将UISearchBar设置为黑色半透明?

ios - UITableView 单元格具有针对三种不同单元格设计的不同标识符

ios - 无法再向我的 Beta 测试人员更新应用 Beta 版(临时)?

ios - 归档 iOS 应用程序 swift 时出错

ios - 本地通知在每个周末重复

swift - Instagram 探索搜索栏和表格 View

ios - UISearchBar iOS 返回索引超出范围的错误