Attached iOS 11-style UISearchBar background image - ios

I'd like to migrate my tableHeaderView based search bar to the new seamless search bar approach in iOS 11 by configuring navigationItem.searchController.
Since my navigation bar uses a custom background image, I'm wondering how to apply the same background image to the search bar as well. I tried
[navigationBar setBackgroundImage:[UIImage imageNamed:#"NavigationBarPromptBackground"] forBarMetrics:UIBarMetricsDefaultPrompt];
[searchBar setBackgroundImage:[UIImage imageNamed:#"NavigationBarBackground"] forBarPosition:UIBarPositionAny barMetrics:UIBarMetricsDefault];
to no avail. The search bar keeps the standard navigation bar background (with a barTintColor applied) but doesn't show the custom background image.

In my case I have a UISearchBar in a view, not placed in a UINavigationItem. A transparent background image I was setting wasn't showing up in iOS 11. However if I add a height constraint that forces the searchBar to be smaller the background image gets used for some reason. This is really odd behavior that must be a bug but it is working for me now.
If I do the following the background image gets used:
[[searchBar.heightAnchor constraintEqualToConstant:44.0] setActive:YES];

I do a very similar thing in my application and discovered on IOS11 it's now broken. This is the code I had which sets my image across the Search and Scope bars, works fine up to IOS10:
[searchBarSearch setBackgroundImage:image];
[searchBarSearch setScopeBarBackgroundImage:image];
I fixed it by adding this to the .plist
View controller-based status bar appearance = NO
Now my bar is coloured and changes as I select different options as it did before IOS11.
Hope this helps you!
Plasma

Related

Set background color (not Text Color) of Back button in UINavigationBar IOS

Is there any way to set the background color of back button in NavigationBar like this
There are some post available on SO which shows how to set Tint color. But can anyone let me know if there is way to set Background Color like shown in image above. or i have to set in custom way?
for navigationBar you should setbackgroundImage
navigationController?.navigationBar.setBackgroundImage(UIImage(named: "your image name"),
forBarMetrics: UIBarMetrics.Default)
I tried with Tint color, but I can not make it work properly.
I do that by adding an UIView at the back of the UINavigationBar. In that case it must be properly positioned using Autolayout.
You have to realize, that is not actually back button background.
If you'll take a closer look at navigation bar, you will see back button has a limited width and height. Something like this:
So if you really need to customize your navigation bar, you have 2 variants:
1) set your navigation bar background image, with fixed or adapting back button background
2) implement custom navigation bar, ignoring system UINavigationBar
You can use custom image and set title manually
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:[UIImage imageNamed:#"customImage"]
forState:UIControlStateNormal
barMetrics:UIBarMetricsDefault];

Change UIWebView Done button color

I am using a UIWebView to display content in an app and would like to change the color of the Done button that is displayed whenever a select control is used.
It is currently displaying as white on gray which is hard to see.
The "Done" button is white because you are probably setting the tintColor to white for all UIBarButtonItems using UIAppearance. That affects the "Done" Button in the picker view which also happens to be a UIBarButtonItem.
So you have to exclude the "Done" button in the picker view from the global white tintColor. I don't know if you only need the white UIBarButtonItems in your navigation bar, but if you do you could do this to only set the tintColor for the bar button items in your navigation bar and leave all other UIBarButtonItems untouched:
UIBarButtonItem.appearanceWhenContainedInInstancesOfClasses([UINavigationBar.self]).tintColor = UIColor.whiteColor()
However this is only available in iOS9 and the old appearanceWhenContainedIn method that works for older iOS versions is not available in Swift.
So, if you are working with Swift and you have to target earlier iOS versions than iOS9 this is probably not working for you. In that case you have to remove the UIAppearance setting for the white tintColor and set the tintColor for the UIBarButtonItems in your navigation bar "manually" without using UIAppearance.
Another possible solution is to just do
UIPickerView.appearance().tintColor = UIColor.blueColor()
put this in your AppDelegate and you are ready to go!

Blurred translucent navigation bar in iOS

I'm trying to get this blur-translucent navigation bar effect (The first navigation bar in the image) in my Swift iOS application:
But I can't get this done. I've tried several methods, some of them are below:
setBackgroundImage, shadowImage and translucent attrs in AppDelegate (Getting the NavController from the RootViewController attr)
Those lines in AppDelegate main method:
UINavigationBar.appearance().translucent = true;
UINavigationBar.appearance().barTintColor = UIColor(white: 1, alpha: 0.4)
Changing attributes from UIBuilder
Setting self.automaticallyAdjustsScrollViewInsets = true and self.edgesForExtendedLayout = UIRectEdge.None in viewControllers
But still can't get this to work. I'm running the app on XCode simulators, using iOS 8.1 and 9.0
What I am doing wrong?
The second navigation bar is already translucent and blurred—it just isn't quite as translucent as the first navigation bar. If you open Digital Color Meter and mouse over your screenshot, you can see that the background of the second navigation bar is darker in the area covering the image.
The reason why the first navigation bar is more translucent than the second navigation bar was explained in this question: the screenshot of the first bar was taken from a device running iOS 7.0.2, whereas the screenshot of the second bar was taken from a device running iOS 7.0.4. Apple changed the behaviour of UINavigationBar between those versions of iOS, and again with iOS 7.1.
Apple explains the current translucency mechanism as follows:
A translucent bar mixes its barTintColor with gray before combining it with a system-defined alpha value to produce the final background color that is used to composite the bar with the content it overlies.
The only description of the blur effect appears to be the following:
Navigation bars are translucent by default in iOS 7. Additionally, there is a system blur applied to all navigation bars.
You can change the transparency of the bar by using UIImage.imageWithColor: to make a background image for the bar from a UIColor with an appropriate alpha value, but doing so will remove the blur effect. There is no documented way to alter the "system-defined alpha value" to increase the translucency of the bar without removing the "system blur".
If you want to imitate the old translucency and blurring effects on iOS 8.1 and 9.0, you'll need to make your own subclass of UINavigationBar and insert one or more subviews such as a UIView with a background color that uses an appropriate alpha value (for transparency) and/or a UIVisualEffectView (for the blur effect).
You might be able to find a combined view in one of the answers to this question.
Related: Blurring effect disappeared on iOS 7.1
Add bellow code in didFinishLaunchingWithOptions:
For Objective C
[[UINavigationBar appearance] setTranslucent:NO];
For Swift 3+/iOS 10+
UINavigationBar.appearance().isTranslucent = false
Maybe plist changes can fix your problem.

Set navigation bottom bar color programatically

Is there away i can set the colour of may navigationController bottom bar colour. Similar to setting top bar in the app delegate with
[[UINavigationBar appearance]setBackgroundColor:color];
can bottomBarColor or something be used?
thanks
The problem is you mistakenly believe that the bar you see at the bottom is a real bar instance/object.
It is not, it is just a simulation of a future situation.
With bar metrics feature in Interface Builder, you can simulate a situation when you view controller will be a part of larger view hierarchy which will contain a bar at a bottom. You can simulate this in design time, and this way you can adjust your AutoLayout constraints, or frames, as if the bar was there so this way the constraints/ frames will behave correctly when it really happens.
If you want a bar with orange colour, you need to have a real bar instance added to some view controller, and change its appearance. But I repeat, it needs to be a real bar instance, not a bar metrics simulation.
Btw, it is AFAIK not possible to put a navigation bar to the bottom, for that you need to use UIToolbar class.
If you want to set the toolbar color globally do this in your AppDelegates didFinishLanchingWithOptions method:
[[UIToolbar appearance] setBarTintColor:[UIColor blackColor]];
Of course your selected color doesn't have to be black.

UIToolbar incorrect colour in iOS7

When I set the bottom UIToolbar to black on the view controller, it appears as a more greyish colour (the same thing happens with other colours--it sort of fades them out). What I assume is happening is that in iOS7 the toolbar seems to adapt the colour of what is beneath it (currently white) which makes for the duller colour.
I've updated the view controller so that the "extended edges" options are turned off but still get this effect. Has anyone else had this issue yet?
UPDATE:
I resolved the issue by setting the background colour of the UIToolbar to black (something I haven't had to do in previous versions of iOS). If anyone can think of a better solution, let me know.
All tool- and navigation bars in iOS 7 have a translucent property.
This causes the effect, where the background shines through in blurred form (just like the control center).
Just set YourToolbar.translucent = NO;.
SET the t*ranslucent property to NO*:-
IN iOS 7 you need to set the barTintColor Property-
UIToolbar *doneToolbar=[[UIToolbar alloc]initWithFrame:CGRectMake(0, 584, 320, 44)];
doneToolbar.translucent=NO;
doneToolbar.barTintColor=[UIColor blackColor];
[self.view addSubview:doneToolbar];
I have used it its working fine...
setting the background color instead of the bar tint worked for me
I set the bar tint to default, the translucent property to NO and the background to the color i wanted and it worked for me.

Resources