Des variantes de cette question ont déjà été posées, mais aucune de ces solutions n'a fonctionné pour moi. J'ai fait à la tableViewHeader le searchBar et c'est ce que j'ai jusqu'ici.Recherche personnaliséeBarre avec bordure
Mon code ressemble à ceci:
override func viewDidLoad() {
super.viewDidLoad()
configureSearchBar()
self.tableView.separatorColor = UIColor(red:0.00, green:0.87, blue:0.39, alpha:1.0)
// Uncomment the following line to preserve selection between presentations
// self.clearsSelectionOnViewWillAppear = false
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
// self.navigationItem.rightBarButtonItem = self.editButtonItem
}
func configureSearchBar() {
searchController.searchBar.delegate = self
searchController.dimsBackgroundDuringPresentation = false
searchController.hidesNavigationBarDuringPresentation = false
searchController.searchBar.placeholder = "Search Companies"
definesPresentationContext = true
tableView.tableHeaderView = searchController.searchBar
searchController.searchBar.barTintColor = UIColor.white
//makes border for search box and gives color and rounded
//searchController.searchBar.layer.borderColor = UIColor(red:0.00, green:0.87, blue:0.39, alpha:1.0).cgColor
//searchController.searchBar.layer.borderWidth = 2.0
//searchController.searchBar.layer.cornerRadius = 15.0
}
Et je suis en train de construire cela, mais jusqu'à présent j'ai échoué
Si j'essaie ceci:
searchController.searchBar.layer.borderColor = UIColor(red:0.00, green:0.87, blue:0.39, alpha:1.0).cgColor
searchController.searchBar.layer.borderWidth = 1.0
searchController.searchBar.layer.cornerRadius = 15.0
searchController.searchBar.clipsToBounds = true
Ça finit par ressembler à ceci, c'est exactement ce que je cherche.
Merci pour votre aide à l'avance
Vous avez plus de chances d'obtenir une réponse utile si vous publiez votre code actuel. – nathan
Copie possible de [Comment changer la bordure et les icônes dans la barre de recherche (Swift)] (https://stackoverflow.com/questions/31413127/how-to-change-border-and-icons-in-search-bar-swift – arvidurs