UISearchBarSearchField BackgroundView color
After a lot more search I found the correct answer that is working for me.
if #available(iOS 11.0, *) {
if let textfield = search.searchBar.value(forKey: "searchField") as? UITextField {
textfield.textColor = UIColor.blue
if let backgroundview = textfield.subviews.first {
backgroundview.backgroundColor = UIColor.white
backgroundview.layer.cornerRadius = 10;
backgroundview.clipsToBounds = true;
}
}
}
How to change color of Search Bar?
Try:
self.mySearchBar.barTintColor = [UIColor redColor];
How to change background color of the text field in the UISearchController?
Here is a an example on how to set the textField
background.
class ViewController: UIViewController {
let searchController = UISearchController(searchResultsController: nil)
private lazy var searchTextField: UITextField? = { [unowned self] in
var textField: UITextField?
self.searchController.searchBar.subviews.forEach({ view in
view.subviews.forEach({ view in
if let view = view as? UITextField {
textField = view
}
})
})
return textField
}()
override func viewDidLoad() {
super.viewDidLoad()
searchController.obscuresBackgroundDuringPresentation = false
searchController.searchBar.placeholder = "Search Candies"
navigationItem.searchController = searchController
definesPresentationContext = true
if let bg = self.searchTextField?.subviews.first {
bg.backgroundColor = .green
bg.layer.cornerRadius = 10
bg.clipsToBounds = true
}
}
}
Result
IOS UISearchBar Background Color In iOS 9
Swift 3
To remove the background altogether, set backgroundImage
to an empty image:
searchBar.backgroundImage = UIImage()
To set a custom background color, use barTintcolor
property:
searchBar.barTintColor = .green
Changing the background color in a search bar
You can do something like this:
instantsearch.widgets.searchBox({
// ...
cssClasses: {
input: 'bg-black',
},
});
And then in your CSS file:
.bg-black {
background-color: black;
}
You're essentially asking InstantSearch to add an additional class called bg-black
to the HTML input element it renders. Then in your CSS, you're targeting that CSS selector and adding styles to it.
More docs here: https://www.algolia.com/doc/api-reference/widgets/search-box/js/#widget-param-cssclasses
Related Topics
Where's the Difference Between Setobject:Forkey: and Setvalue:Forkey: in Nsmutabledictionary
Developing for iOS Device in Windows Environment with Flutter
How to Remove the Default Navigation Bar Space in Swiftui Navigationview
Rsa Implementations in Objective C
Detect First Launch of iOS App
How to Change Locale Programmatically with Swift
How to Get an Iso 8601 Date on iOS
How to Change Inside Background Color of Uisearchbar Component on iOS
How to Set the Opacity/Alpha of a Uiimage
Comparing Nsdates Without Time Component
iOS 8 Sdk: Modal Uiwebview and Camera/Image Picker
Crashlytics: "We'Re Missing a Dsym to Process Crashes"
Dyld'_Abort_With_Payload: Without an Error Message
Connect Objective-C Framework to Swift iOS 8 App (Parse Framework)
How to Display .Svg Image Using Swift