UISearchBar cannot be copied as it doesn't adopt NSCopying.
You have to create a new instance of UISearchBar
and apply the customizations, for this you can also create an struct that holds the settings, like so:
struct SearchBarConfig {
var placeholder: String?
var isTranslucent: Bool
// Display Attributes
var barStyle: UIBarStyle
var barTintColor: UIColor?
var searchBarStyle: UISearchBarStyle
var tintColor: UIColor!
init(isTranslucent: Bool, barStyle: UIBarStyle, searchBarStyle: UISearchBarStyle) {
self.isTranslucent = isTranslucent
self.barStyle = barStyle
self.searchBarStyle = searchBarStyle
}
}
let existingSearchBar = UISearchBar()
var existingStatusBarConfig = SearchBarConfig(
isTranslucent: existingSearchBar.isTranslucent,
barStyle: existingSearchBar.barStyle,
searchBarStyle: existingSearchBar.searchBarStyle)
Now if you have above implemented, you can just create a new searchBar and apply the attributes.