我遇到了为UISearchBar设置自定义背景的问题。 UISearchBar作为UITableView的标题添加。对于设置背景,我使用下一行:
UISearchBar.appearance().setSearchFieldBackgroundImage(UIImage(named: "search_field"), forState: .Normal)
UISearchBar.appearance().setBackgroundImage(UIImage(named: "search_bar_background"), forBarPosition: .Top, barMetrics: .Default)
UISearchBar.appearance().setImage(UIImage(named: "search_icon"), forSearchBarIcon: .Search, state: .Normal)