Программируем под IOS
Anonymous
Как изменить цвет фона серой области в строке поиска на белый?
Сообщение
Anonymous » 26 апр 2024, 19:00
Код: Выделить всё
let searchBar = UISearchBar()
searchBar.placeholder = ChatConstants.searchTitle
searchBar.backgroundColor = .white
searchBar.delegate = self
searchBar.vCornerRadius = 20
searchBar.vBorderWidth = 1
searchBar.vBorderColor = .icedGray
searchBar.searchBarStyle = .minimal
searchBar.searchTextField.backgroundColor = .white
searchBar.translatesAutoresizingMaskIntoConstraints = false
if let textField = searchBar.value(forKey: ExploreConstants.searchFieldKey) as? UITextField {
let whiteColor = UIColor.white
let attributedString = NSAttributedString(string: "Search", attributes: [NSAttributedString.Key.foregroundColor: whiteColor])
textField.attributedPlaceholder = attributedString
textField.font = UIFont.regularDMSans(of: ExploreConstants.textFieldFontSize)
textField.layer.cornerRadius = ExploreConstants.searchBarCornerRadius
if let searchIcon = UIImage(named: ExploreConstants.iconExploreSearch) {
let imageView = UIImageView(image: searchIcon)
let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: ExploreConstants.searchIconOffset + searchIcon.size.width, height: searchIcon.size.height))
imageView.frame = CGRect(x: ExploreConstants.searchIconOffset, y: 0, width: searchIcon.size.width, height: searchIcon.size.height)
paddingView.addSubview(imageView)
textField.leftView = paddingView
textField.leftViewMode = .always
}
}
Я настраиваю панель поиска, как показано выше. Однако мне не удалось сделать серую область на изображении белой. Как изменить эту область на белую?
Я ожидал, что если изменить цвет фона UIView на белый, серая область в строке поиска также станет белой.
Подробнее здесь:
https://stackoverflow.com/questions/783 ... ar-to-whit
1714147206
Anonymous
[code]let searchBar = UISearchBar() searchBar.placeholder = ChatConstants.searchTitle searchBar.backgroundColor = .white searchBar.delegate = self searchBar.vCornerRadius = 20 searchBar.vBorderWidth = 1 searchBar.vBorderColor = .icedGray searchBar.searchBarStyle = .minimal searchBar.searchTextField.backgroundColor = .white searchBar.translatesAutoresizingMaskIntoConstraints = false if let textField = searchBar.value(forKey: ExploreConstants.searchFieldKey) as? UITextField { let whiteColor = UIColor.white let attributedString = NSAttributedString(string: "Search", attributes: [NSAttributedString.Key.foregroundColor: whiteColor]) textField.attributedPlaceholder = attributedString textField.font = UIFont.regularDMSans(of: ExploreConstants.textFieldFontSize) textField.layer.cornerRadius = ExploreConstants.searchBarCornerRadius if let searchIcon = UIImage(named: ExploreConstants.iconExploreSearch) { let imageView = UIImageView(image: searchIcon) let paddingView = UIView(frame: CGRect(x: 0, y: 0, width: ExploreConstants.searchIconOffset + searchIcon.size.width, height: searchIcon.size.height)) imageView.frame = CGRect(x: ExploreConstants.searchIconOffset, y: 0, width: searchIcon.size.width, height: searchIcon.size.height) paddingView.addSubview(imageView) textField.leftView = paddingView textField.leftViewMode = .always } } [/code] [b]Я настраиваю панель поиска, как показано выше. Однако мне не удалось сделать серую область на изображении белой. Как изменить эту область на белую?[/b] [img]https://i.sstatic.net/jtgGRuYF.png[/img] Я ожидал, что если изменить цвет фона UIView на белый, серая область в строке поиска также станет белой. Подробнее здесь: [url]https://stackoverflow.com/questions/78391631/how-can-i-change-the-background-color-of-the-gray-area-in-the-search-bar-to-whit[/url]
0 Ответы
0 Просмотры
Последнее сообщение Anonymous
09 мар 2024, 15:48
0 Ответы
1 Просмотры
Последнее сообщение Гость
09 мар 2024, 20:34
0 Ответы
5 Просмотры
Последнее сообщение Гость
21 сен 2023, 20:29
0 Ответы
5 Просмотры
Последнее сообщение Гость
22 сен 2023, 14:17
0 Ответы
5 Просмотры
Последнее сообщение Гость
22 сен 2023, 14:17