UISearchBar 的默认 barTintColor 和 backgroundColor

Default barTintColor and backgroundColor for UISearchBar

我正在尝试使用 UIAppearance 准确地重新创建默认 UISearchBar 的外观。问题是,当我尝试获取标题中变量的值时,它们为零。

我已经尝试了 [[UISearchBar appearance] barTintColor]self.searchBar.barTintColor 但无济于事。

我用Utilities文件夹中的DigitalColor Meter正常获取了bar的值,然后设置背景为白色,设置barTintColor为测量值。这几乎奏效了,但是 'cancel' 按钮混合在一起,并且搜索栏的顶部和底部出现了黑线。

所以我要么需要两种颜色的默认值,要么需要一种读取所述默认值的方法。

鉴于没有人回答并且此 post 在相关 google 搜索结果中排名靠前,我想给出最终为我解决的答案。

只需将颜色设置为 nil 即可使它们使用默认值。