How can the appearance of Button Shapes enabled through the Accessibility settings be influenced in iOS 7.1?

旧城冷巷雨未停 提交于 2019-12-04 04:06:24

This feature seems to be a little buggy in iOS 7.1. The setting that seems to influence the appearance the most is actually the barTintColor on your UINavigationBar.

Some examples:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[UINavigationBar appearance] setBarTintColor:[UIColor lightGrayColor]];

    return YES;
}

When I first launch, the back button looks fine:

Then when I go to landscape, it looks way too dark:

And it then stays too dark when I go back to portrait:

The same thing happens when I use [UIColor orangeColor] as the barTintColor. First it`s fine:

In landscape it gets messed up:

And it then stays that way:

So it clearly looks like a bug in iOS 7.1. One thing that can be done is to set a background image for the back button. This background will then display whether "Button Shapes" is activated or not. Example:

UIImage *backButtonImage = [[UIImage imageNamed:@"back_button.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(0.0f, 17.0f, 0.0f, 1.0f) resizingMode:UIImageResizingModeStretch];

[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsDefault];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateHighlighted barMetrics:UIBarMetricsDefault];

[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateNormal barMetrics:UIBarMetricsLandscapePhone];
[[UIBarButtonItem appearance] setBackButtonBackgroundImage:backButtonImage forState:UIControlStateHighlighted barMetrics:UIBarMetricsLandscapePhone];

So the big question is: Can we set the button background image when "Button Shapes" is turned on in a way that is independent of the barTintColor?

-[UINavigationBar setTranslucent:NO] seems to correct this. I don't know why, but it does.

Alas, we couldn't set -[UINavigationBar setTranslucent:] using UIAppearance so had to sprinkle it around the app.

I just ran into an issue similar to one described in the comments of one of the answers here while using a barTint color fairly close to black. My button shape backgrounds were nearly the same color as the barTint on a few of my UINavigationBar instances, rendering them almost impossible to see (especially when the buttons were not enabled). I tracked down the difference in these instances to be the value of the UINavigationBar instances barStyle property.

With barStyle set to UIBarStyleDefault, the button shapes would show up with a background color. With barStyle set to UIBarStyleBlack, the buttons shapes would show up with a light color. You can also notice this in the storyboard, as the title shown in the navigation bar will be black with the default style and white with the black style.

You can change each navigation bar's style in your storyboard/NIB, or alternatively you can add the following line of code where you setup your appearance proxies (typically in application:didFinishLaunchingWithOptions:):

[[UINavigationBar appearance] setBarStyle:UIBarStyleBlack];
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!