searchbar color ios 11 - ios

I am trying to change the color of my search bar the problem is when I do the cancel button loses its color and I am unable to see it. If you have any ideas please let me know. Thank you!
Code:
self.searchController = UISearchController.init(searchResultsController: searchDataSource)
self.searchController?.obscuresBackgroundDuringPresentation = true
self.searchController?.searchBar.delegate = self
self.searchController?.searchBar.showsCancelButton = true
self.searchController?.searchBar.placeholder = "Search for items"
self.searchController?.searchBar.isTranslucent = false
self.searchController?.searchBar.barTintColor = UIColor.white
self.searchController?.searchBar.tintColor = UIColor.black

Related

How to fix the position of searchbar us

I'm try to build search function using tutorial from https://www.thorntech.com/2016/01/how-to-search-for-location-using-apples-mapkit/
I need to change his code
because as you can see from the picture if I do navigationitem.titleview the plus button disappears. I want to use searchbar when I searching but I couldn't find a way to do it
let searchBar = resultSearchController!.searchBar
searchBar.sizeToFit()
searchBar.placeholder = "Search for places"
navigationItem.titleView = resultSearchController?.searchBar
resultSearchController?.hidesNavigationBarDuringPresentation = false
resultSearchController?.dimsBackgroundDuringPresentation = true
definesPresentationContext = true
locationSearchTable.mapView = mapView
locationSearchTable.handleMapSearchDelegate = self
Instead of
navigationItem.titleView = resultSearchController?.searchBar
Try
navigationItem.searchController = resultSearchController

UITabBarItem font changes after the tab bar gets hidden

I have experienced a strange issue in the app where the selected tab bar colour changes from the colours I have set back to the tint colour after opening a view controller with the following option:
hidesBottomBarWhenPushed = true
Here is the code I have used to set the font colour prior to finding the issue inside of the initialiser of my customer UITabBarController:
let attributes = ...
UITabBarItem.appearance().setTitleTextAttributes(attributes, for: .normal)
I couldn't find a similar issue on StackOverflow and managed to figure out the solution with the help of the team in my company, so I thought I would share it here in case it helps anybody in the future.
The only way to fix the above issue that we've managed to find is adding the following code to the initializer of our customer UITabBarViewController
if #available(iOS 13, *) {
let appearance = UITabBarAppearance()
appearance.backgroundColor = UIColor.white
appearance.shadowImage = UIImage()
appearance.shadowColor = UIColor.white
let defaultAttributes = ...
appearance.stackedLayoutAppearance.normal.iconColor = UIColor.red
appearance.stackedLayoutAppearance.normal.titleTextAttributes = defaultAttributes
appearance.stackedLayoutAppearance.selected.iconColor = UIColor.red
appearance.stackedLayoutAppearance.selected.titleTextAttributes = attributes
tabBar.standardAppearance = appearance
}

Interaction with search bar does not work swift

I am including a search bar by code and enabling interaction using the code below, the search bar is displayed but when I click on the field editing is not enabled:
let searchTableViewController = storyboard?.instantiateViewController(withIdentifier: "SearchBarTableVC") as? SearchBarTableVC
searchTableViewController?.handleMapSearchDelegate = self
searchTableViewController?.mapView = self.mapView
searchBarController = UISearchController(searchResultsController: searchTableVC)
searchBarController?.searchResultsUpdater = searchTableVC
let searchBar = searchBarController?.searchBar
searchBar?.sizeToFit()
searchBar?.placeholder = "Digite o local"
searchBar?.tintColor = UIColor.red
searchBar!.isUserInteractionEnabled = true
searchBar?.backgroundColor = UIColor(named: "ColorTransparent")
navigationItem.titleView = searchBarController?.searchBar
searchBarController?.hidesNavigationBarDuringPresentation = false
searchBarController?.dimsBackgroundDuringPresentation = true
definesPresentationContext = true
If you're using iOS 11, the preferred way is simply to write:
navigationItem.searchController = searchController
That's all. You don't have to position the search bar or put it in any view.

set tab bar to transparent but can't bring it back to default style

I was able to set my tabBar to transparent with the code below but I don't know how to bring it back to default style. Please help if you can and thank you very much!
tabBarController?.tabBar.backgroundColor = .clear
tabBarController?.tabBar.backgroundImage = UIImage()
tabBarController?.tabBar.shadowImage = UIImage()
Before setting your tab bar to clear color save all the properties
let originalBackgroundImage = tabBarController?.tabBar.backgroundImage
let originalshadowImage = tabBarController?.tabBar.shadowImage
let originalbackgroundColor = tabBarController?.tabBar.backgroundColor
then change to clear color
tabBarController?.tabBar.backgroundColor = .clear
tabBarController?.tabBar.backgroundImage = UIImage()
tabBarController?.tabBar.shadowImage = UIImage()
Finally when you need it back
tabBarController?.tabBar.backgroundColor = originalbackgroundColor
tabBarController?.tabBar.backgroundImage = originalBackgroundImage
tabBarController?.tabBar.shadowImage = originalshadowImage
Finally call layoutIfNeeded on tabBar
Hope it helps

changing searchBar Placeholder text Alignment to left iOS swift [duplicate]

This question already has answers here:
How to left align UISearchBar placeholder text
(10 answers)
Closed 6 years ago.
here is the code for my searchBar
self.searchResultsController = ({
let controller = UISearchController(searchResultsController: nil)
controller.searchResultsUpdater = self
controller.dimsBackgroundDuringPresentation = false
controller.hidesNavigationBarDuringPresentation = false
controller.searchBar.sizeToFit()
controller.searchBar.placeholder = "Type your word here"
//dcontroller.view.backgroundColor = UIColor.blackColor()
controller.searchBar.barTintColor = UIColor.blackColor()
self.tableVw.tableHeaderView = controller.searchBar
return controller
})()
when i click on search bar the code becomes left align but before that it is always scattered
You can use whitespace to achieve this!!
let searchBar: UISearchBar = UISearchBar() //your searchbar
searchBar.placeholder = "Search "
Hope this will help :)

Resources