如何在iOS 7.1中影响通过辅助功能设置启用的按钮形状的外观?

时间:2014-03-13 09:11:20

标签: ios ios7.1

enter image description here

iOS 7.1的发布带来了辅助功能设置按钮形状的可用性。我注意到它们的外观在我的应用中可能不一致。大多数情况下,在使用Interface Builder实现UIBarButtonItem之后,我获得了黑色背景。触摸按钮但未完全点击它会导致图像变灰。如何影响按钮形状的外观,使它们看起来不那么不合适,因为它们具有坚实的黑色背景,更像是附图中所示的灰色背景?在这种情况下,我不想使用自定义控件。

3 个答案:

答案 0 :(得分:4)

这个功能似乎在iOS 7.1中有点小问题。似乎影响外观最多的设置实际上是barTintColor上的UINavigationBar

一些例子:

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

    return YES;
}

首次启动时,后退按钮看起来不错:

enter image description here

然后当我去景观时,它看起来太暗了:

enter image description here

当我回到肖像时它会变得太暗:

enter image description here

当我使用[UIColor orangeColor]作为barTintColor时,会发生同样的事情。 首先它很好:

enter image description here

在风景中它变得混乱:

enter image description here

然后它保持这种状态:

enter image description here

所以它看起来像是iOS 7.1中的一个错误。可以做的一件事是为后退按钮设置背景图像。然后,此背景将显示"按钮形状"被激活与否。例如:

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];

所以最大的问题是:我们可以设置按钮背景图像"按钮形状"是以独立于barTintColor

的方式打开的

答案 1 :(得分:2)

-[UINavigationBar setTranslucent:NO]似乎纠正了这一点。我不知道为什么,但确实如此。

唉,我们无法使用-[UINavigationBar setTranslucent:]设置UIAppearance,所以不得不将其洒在应用程序周围。

答案 2 :(得分:1)

我遇到的问题类似于其中一个答案的评论中描述的问题,同时使用非常接近黑色的barTint颜色。我的按钮形状背景几乎与我的UINavigationBar个实例上的barTint颜色相同,几乎无法看到它们(特别是当按钮未启用时)。我将这些实例中的差异跟踪为UINavigationBar实例barStyle属性的值。

barStyle设置为UIBarStyleDefault时,按钮形状将显示背景颜色。将barStyle设置为UIBarStyleBlack后,按钮形状将显示为浅色。您还可以在故事板中注意到这一点,因为导航栏中显示的标题将为黑色,默认样式为白色,黑色为黑色。

您可以在故事板/ NIB中更改每个导航栏的样式,或者您可以在设置外观代理的位置添加以下代码行(通常在application:didFinishLaunchingWithOptions:中):

[[UINavigationBar appearance] setBarStyle:UIBarStyleBlack];