I was wondering if there is any other way (some hack/trick) to change the layout/theme of NavigationBar and SearchBar without using appearance() in GMSAutocompleteViewController? I want to avoid using that because for example if I change the NavigationBar tint (background) or SearchBar text color using appearance(), it changes for all viewController inside the app.
Here is the official documentation from google: https://developers.google.com/places/ios-sdk/autocomplete#customize_text_and_background_colors
Thanks in advance!
Related
I know SearchDisplayController is deprecated, but Storyboard still supports it, and it is an easy way to present tableViewController on top of your view controller. I have been using it, and I would still prefer to use that. And in iOS 11, when I run my app, the status bar of the SearchDisplayController. after the search bar is focused, is pitch BLACK. Does anyone know how to solve this bug? Also if you realize, the margins of the searcher is off. I am using the default iOS 11 searchbar. Below is attached screenshot:
Have you tried to set the extendedLayoutIncludesOpaqueBars property to true?
searchDisplayController.extendedLayoutIncludesOpaqueBars = true
This is not the best solution actually, but It works to change status bar color.
if let statusBar = UIApplication.shared.value(forKeyPath: "statusBarWindow.statusBar") as? UIView {
statusBar.backgroundColor = //YOUR COLOR HERE
}
Keep in mind this will affect the whole app. If you need to change some views only then save the previous color to restore it.
Regards.
I'm currently re-building an app that using the PlacePicker from Google Place API to get data that user can then add on my map.
In the past, I used the GMSPlacePicker which is now deprecated since Google release their Place API 2.3. So I'm currently trying to migrate to their new way of using the API via a GMSPlacePickerViewController which according to Google can be implemented with Custom UI.
From Google's documentation:
As the place picker is a normal view controller it can be displayed
any way you want. For example, in a popover, fullscreen, pushed onto a
navigation stack, or even as part of a custom app UI.
I have managed to make the GMSPlacePickerViewController part of my broader navigation controller which lets me go back and forth inside the place picker's screens, however I haven't yet managed to customise the UI of the search bar that we see on the third screen on the image below.
Issue:
The text inside the SearchBar is black, and I want to make it white but I do not know how to access the searchBar and its properties as everything seems to be abstracted in the framework. I would also like to change the title 'Select a location' (screen 2) to something smaller.
Any thoughts? Thanks in advance
You should be able to change this with UIAppearance proxies, as described in Use the UIAppearance Protocol (GMSPlacePickerViewController uses a GMSAutocompleteViewController internally).
// Color of typed text in the search bar.
NSDictionary *searchBarTextAttributes = #{
NSForegroundColorAttributeName: lightGray,
NSFontAttributeName : [UIFont systemFontOfSize:[UIFont systemFontSize]]
};
[UITextField appearanceWhenContainedInInstancesOfClasses:#[[UISearchBar class]]]
.defaultTextAttributes = searchBarTextAttributes;
Andrew's answer worked for me in the end. I have converted it to Swift 3.0 for those who might need that in the future. You can simply add the following to your AppDelegate.swift file in didFinishLaunchingWithOptions:
Also searchBarTextAttributes is a dictionary so feel free to add more properties in there to customize even further.
let searchBarTextAttributes = [NSForegroundColorAttributeName: UIColor.white]
UITextField.appearance(whenContainedInInstancesOf:[UISearchBar.self]).defaultTextAttributes = searchBarTextAttributes
I'm using XCTest and want to test the navBar of a tableView to see if it is set to a specific colour.
How do I reference the colour of the navBar?
Kind regards
For the navigation bar, you likely want navigationBar.barTintColor for the background color.
I'm creating an app that needs to display the darker keyboard (UIKeyboardAppearanceDark) in iOS7 for a UIWebView text field.
Basically, I'm posting a video to Facebook (using ESSVideoShare), by logging in through a web view Facebook login page. And for the keyboard that appears when you touch the WebView is the default white keyboard in iOS7. I would like to change this to be the darker keyboard to keep the theme of the app consistent.
I managed to do this for the UITextFields by doing :
editableTextField.keyboardAppearance = UIKeyboardAppearanceDark;
But I wasn't able to find a way to access the keyboard or appearance properties of UIWebView.
This app is not going into the app store and thus I can use private APIs, if there are no public API available to achieve this.
Any help will be greatly appriciated.
Try with this and use this method in ViewWillAppear so appearance can be set before view is loading.
[[UITextField appearance] setKeyboardAppearance:UIKeyboardAppearanceDark];
make UIWebBrowserView implement keyboardAppearance method
Apple does not provide any property in UIWebView class to make keyboard appearance dark in UIWebView.
You may like to make background colour of keyboard dark which you can accomplish by adding a subview behind keyboard that shows and hide with keyboard appearance.
The https://github.com/meekapps/TintedKeyboard has the library which does this.
I read many posts on customizing color of selected tabbar item which is actually blue by default.
My idea was to put an UIImageView on each of my button.
Once the user select one button, I would then display the image (which is the same icon but with another colour as a gradient).
What do you think about that ?
Thanks in advance
You could always use this http://idevrecipes.com/2011/01/04/how-does-the-twitter-iphone-app-implement-a-custom-tab-bar/ and change it to include text and modify the colour.
Thankfully, iOS 5 introduced an appearance proxy allowing customisation of most basic UI elements, including the trusty UITabBar. The proxy is used to change ALL instances of a class throughout an application. However, with this came some basic properties available for specific instances.
See the selectedImageTintColor property of UITabBar for your needs.
Other appearance additions for this class are tintColor, backgroundImage and selectionIndicatorImage.