更改 UISearchController 的 UINavigationBar 背景色

Change UINavigationBar Background Color of UISearchController

此刻,我的搜索控制器 "navigation bar" 背景是标准的默认半透明背景,但是,我应用中的所有其他栏都是黑色半透明的。当我打印 searchController 的 navigationController 属性 时,它 returns nil 并且 navigationBar 也是如此,但不是 navigationItem。似乎没有其他 public 属性可以让您更改栏的颜色。我不介意覆盖私有 ivar,因为我不会在应用商店中发布此应用。

您可以使用 barTintColor 属性,在 Swift 中将是:

searchBar.barTintColor = UIColor.redColor()