IOS - prohibition of UIAppearance settings to change the appearance of the auxiliary input device UIWebView

I have a UIWebView in my application and the problem is that I have a UIAppearance that changes the appearance of the segmented controls, so it changes the segmented control in the auxiliary input view for the UIWebView text fields, I would like it to look right or not try to change it. It looks like this:

enter image description here

+7
source share
2 answers

I just solved this problem for myself using [UIAppearance appearanceWhenContainedIn:] instead of [UIAppearance appearance].

Use it by sending the selector a null-terminated list of all your custom ViewController classes that contain the elements you want to customize. Therefore, instead of

[[UISegmentedControl appearance] setBackgroundImage:buttonBackgroundImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 

use

 [[UISegmentedControl appearanceWhenContainedIn:[MyViewController class], [MyOtherViewController class], nil] setBackgroundImage:buttonBackgroundImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 

You do not need to list all ViewControllers, only your top levels. It also allows you to do the following trick: create an "empty" subclass of CustomizedViewController UIViewController, which does nothing more than a subclass, and then subclass from there on your code instead of UIViewController (basically replace all occurrences of "UIViewController" with "CustomizedViewController", except cases where the CustomizedViewController actually declared the UIViewController its superclass.

Then use

 [[UISegmentedControl appearanceWhenContainedIn:[CustomizedViewController class], nil] setBackgroundImage:buttonBackgroundImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault]; 
+5
source

Ok, so I was finally able to figure out a workaround for this. See my comment on the current answer, which explains why this answer does not work for me.

To repeat the iteration, from what I can tell, the iOS code creating the keyboard accessory explicitly sets the UIToolbar background, so you won’t get the UIAppearance background setting, but you get your UIBarButtonItem style. The result is a dilapidated look that can look pretty bad. Fortunately, my designer was fine with a return to the default style for this particular case.

So the trick really was to figure out how to get this look, so as NOT to get the style through UIAppearance. I did this to replace this:

 id barButtonAppearanceProxy = [UIBarButtonItem appearance]; 

Wherein:

 // wtf: Style any UIBarButtonItem associated with a UIViewController id barButtonAppearanceProxy = [UIBarButtonItem appearanceWhenContainedIn:[UIViewController class], nil]; 

At first it seemed strange to me because I was thinking about restraint in terms of view-heirarchy ... But it just says that we will only stylize the UIBarButtonItems associated with the UIViewController. The reason this does not affect the keyboard accessory is because it directly added the parent view window and is not related to the UIViewController.

This is not an ideal solution, because ideally we would simply attach the keyboard to the accessory with UIAppearance. It is also assumed that all of your toolbars are associated with UIViewControllers. Fortunately for me (and probably for most of you) this is usually the case.

+2
source

All Articles