iOS 7.1 的发布在辅助功能设置下提供了按钮形状。我注意到它们的外观在我的应用程序中可能不一致。大多数情况下,在使用 Interface Builder 实现 UIBarButtonItem
后,我得到了黑色背景。触摸按钮但未完全点击它会导致图像变灰。如何影响按钮形状的外观,使它们看起来不会像具有纯黑色背景那样不合时宜,更像是附图中所示的灰色背景?在这种情况下,我不想使用自定义控件。
最佳答案
这个功能在 iOS 7.1 中似乎有点问题。似乎对外观影响最大的设置实际上是 UINavigationBar
上的 barTintColor
。
一些例子:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[UINavigationBar appearance] setBarTintColor:[UIColor lightGrayColor]];
return YES;
}
当我第一次启动时,后退按钮看起来不错:
然后当我去风景时,它看起来太暗了:
当我回到纵向时,它仍然太暗:
当我使用 [UIColor orangeColor]
作为 barTintColor
时,同样的事情发生了。
首先它很好:
在景观中它变得困惑:
然后它就这样了:
所以它显然看起来像是 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
的方式设置按钮背景图像?
关于ios - 在 iOS 7.1 中如何影响通过辅助功能设置启用的按钮形状的外观?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22373815/