[英]UITabBarItem icon not colored correctly for iOS 13 when a bar tint color is specified in Interface Builder in Xcode 11, beta 2
[英]using xcode 5 interface builder for setting tab bar tint (background) color
我对ios开发很陌生,我有以下问题。 在xcode 5的情节提要中设计tabBar时,我意识到我无法为ios 6设置tabBar的背景色。
这似乎与以下事实有关:在ios6中,bar backgroundcolor为tintColor,而在ios 7中,其变为了barTintColor。
如果将情节提要的“查看方式”参数更改为“ iOS 6.1和Ealier”,则会看到背景颜色从我在属性编辑器(Bar Tint)中设置的正确值更改为iOS 6的标准值。
当然,我可以从代码中设置值,但这对可维护性不利。
有什么办法可以在xcode 5接口构建器中为iOS 6定义此值?
更新:由于到目前为止,我还没有找到令人满意的解决方案,因此我使用以下解决方法。 我在属性检查器中将tabBar的背景色设置为视图中的属性“ Bar Tint”和“ Background”。 在我的应用程序委托中,我使用以下代码:
UITabBarController *tabBarController = (UITabBarController *)self.window.rootViewController;
UITabBar *tabBar = tabBarController.tabBar;
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 7) {
[tabBar setSelectedImageTintColor:tabBar.tintColor];
tabBar.tintColor = tabBar.backgroundColor;
}
我遇到了同样的问题。 不幸的是,您将必须使用类似于以下内容的代码来保留iOS 6的兼容性:
// iOS 6 compatibility
NSString *reqSysVer = @"7.0";
NSString *currSysVer = [[UIDevice currentDevice] systemVersion];
if ([currSysVer compare:reqSysVer options:NSNumericSearch] == NSOrderedAscending) {
[[UINavigationBar appearance] setTintColor:[UIColor colorWithRed:66.f/255.f green:173.f/255.f blue:179.f/255.f alpha:1.f]];
[[UIBarButtonItem appearance] setTintColor:[UIColor colorWithRed:66.f/255.f green:173.f/255.f blue:179.f/255.f alpha:1.f]];
}
我不确定InterfaceBuilder中的'tint'为什么不起作用,但这不是我们的目的。
注意:如果要支持iOS <5.0,则必须修改iOS版本检查,因为UIAppearance协议仅在iOS 5.0之后可用
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.