Swift 3, je suis en train de changer la couleur du texte des barres de recherche du bleu au noir. Par exemple le "annuler" et les barres de portée bleu et la couleur de la bordure est bleu, je le veux noir.Comment changer les couleurs de la barre de recherche?
C'est ce que j'ai.
Et j'ai essayé cette ligne, mais je ne sais pas assez et cette ligne ne fonctionne pas comme vous pouvez le voir.
searchController.searchBar.setScopeBarButtonTitleTextAttributes([NSBackgroundColorAttributeName: UIColor.black], for: UIControlState.normal)
viewDidLoad
// Search Bar
searchController.searchResultsUpdater = self
searchController.dimsBackgroundDuringPresentation = false
definesPresentationContext = true
myTableView.tableHeaderView = searchController.searchBar
// Search Bar Border
let searchBar = searchController.searchBar
searchBar.backgroundImage = UIImage()
// Scope Bar
searchController.searchBar.scopeButtonTitles = ["All", "Released", "Unreleased", "Open Beta"]
searchController.searchBar.delegate = self
reste du Code SearchBar
// SEARCH BAR: Filtering Content
func filterContentForSearchText(searchText: String, scope: String = "All") {
filteredFollowedArray = followedArray.filter { Blog in
let categoryMatch = (scope == "All") || (Blog.blogType == scope)
return categoryMatch && (Blog.blogName.lowercased().contains(searchText.lowercased()))
}
filteredBlogArray = blogArray.filter { Blog in
let categoryMatch = (scope == "All") || (Blog.blogType == scope)
return categoryMatch && (Blog.blogName.lowercased().contains(searchText.lowercased()))
}
myTableView.reloadData()
}
// SEARCH BAR: Updating Results
func updateSearchResults(for searchController: UISearchController) {
filterContentForSearchText(searchText: searchController.searchBar.text!)
}
func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) {}
func searchBarTextDidEndEditing(_ searchBar: UISearchBar) {}
func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) {}
// SEARCH BAR: Scope
func searchBar(_ searchBar: UISearchBar, selectedScopeButtonIndexDidChange selectedScope: Int) {
filterContentForSearchText(searchText: searchBar.text!, scope: searchBar.scopeButtonTitles![selectedScope])
}
// SEARCH BAR: Updating Scope
func updateSearchResultsForSearchController(searchController: UISearchController) {
let searchBar = searchController.searchBar
let scope = searchBar.scopeButtonTitles![searchBar.selectedScopeButtonIndex]
filterContentForSearchText(searchText: searchController.searchBar.text!, scope: scope)
}
// Deallocating Search Bar
deinit{
if let superView = searchController.view.superview {
superView.removeFromSuperview()
}
}
nouveau code:
// Search Bar
searchController.searchBar.backgroundColor = UIColor.white
searchController.searchBar.barTintColor = UIColor.white
// Coloring SearchBar Cancel button
let cancelButtonAttributes: NSDictionary = [NSForegroundColorAttributeName: UIColor.black]
UIBarButtonItem.appearance().setTitleTextAttributes(cancelButtonAttributes as? [String : AnyObject], for: UIControlState.normal)
// Scope: Selected text
let titleTextAttributesSelected = [NSForegroundColorAttributeName: UIColor.white]
UISegmentedControl.appearance().setTitleTextAttributes(titleTextAttributesSelected, for: .selected)
// Scope: Normal text
let titleTextAttributesNormal = [NSForegroundColorAttributeName: UIColor.black]
UISegmentedControl.appearance().setTitleTextAttributes(titleTextAttributesNormal, for: .normal)
Mais la barre est toujours portée bleu et il doit être noir
cela a fonctionné pour le bouton d'annulation, mais pas la barre de portée, il est toujours – BroSimple
bleu @BroSimple, vérifiez la mise à jour pour voir comment changer la couleur du texte de votre commande segmentée. –
merci! mais maintenant tout le texte dans les boutons de la barre de champ changé, il y a encore bleu dans la limite de la portée et le texte sélectionné a encore le bleu, (dans le pic j'ai le « All » qui a le fond bleu dans le texte sélectionné – BroSimple