撤消单屏幕iOS的搜索栏背景图像

撤消单屏幕iOS的搜索栏背景图像,ios,objective-c,uiimage,Ios,Objective C,Uiimage,我正在一个包含搜索栏的页面上工作。因此我使用了uisearch控制器 在app delegate中,我们通过将图像添加到背景中,更改了UISearchBar的外观 UISearchBar.appearance().setBackgroundImage(UIImage(named: "search-bg"), for: UIBarPosition.any, barMetrics: UIBarMetrics.default) 现在,当我在viewcontroller中使用searchControl

我正在一个包含搜索栏的页面上工作。因此我使用了
uisearch控制器

在app delegate中,我们通过将图像添加到背景中,更改了
UISearchBar
的外观

UISearchBar.appearance().setBackgroundImage(UIImage(named: "search-bg"), for: UIBarPosition.any, barMetrics: UIBarMetrics.default)
现在,当我在viewcontroller中使用searchController时,点击搜索栏时,搜索栏上似乎有一个黑色的窗帘视图:

当我删除
UISearchBar.appearance().setBackgroundImage
时,搜索栏看起来不错。但我需要在搜索栏中进行更改,因此我尝试通过设置以下内容来更改背景图像:

self.searchBar.backgroundImage = UIImage.init()
但这也不起作用

是否有方法撤消一个viewcontroller的背景图像?或者其他方法来实现这一点?

尝试以下方法:

let appearence =  UISearchBar.appearanceWhenContainedInInstancesOfClasses([ViewController.classForCoder()])
appearence.setBackgroundImage(UIImage.init(named: "search-bg"), forBarPosition: UIBarPosition.Any, barMetrics: UIBarMetrics.Default)

这将允许我使用UIImage.init()初始化它,但不会撤消效果。如何设置无映像。请为所需的视图控制器设置自定义bg映像,或仅为不需要自定义bg的视图控制器设置默认bg映像。注意:您必须将默认bg映像添加到您的资源中,设置没有映像引用的UIImage将没有帮助。