xcode 如何将图像背景设置为 UITabBarController iOS 5
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7779736/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to set image background to UITabBarController iOS 5
提问by bilbo
Hello can someone help me with this pice of code. I have app with custom tab bar image an now in iOS5 the image is gone. I know that they have made changes on tab bar implementation and i'm not sure how to fix this.
你好,有人可以帮我处理这段代码。我有带有自定义标签栏图像的应用程序,现在在 iOS5 中图像消失了。我知道他们对标签栏的实现进行了更改,但我不知道如何解决这个问题。
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[window makeKeyAndVisible];
CGRect frame = CGRectMake(0, 0, 400, 148);
UIView *viewa = [[UIView alloc] initWithFrame:frame];
UIImage *tabBarBackgroundImage = [UIImage imageNamed:@"fasha-down.png"];
UIColor *color = [[UIColor alloc] initWithPatternImage:tabBarBackgroundImage];
[viewa setBackgroundColor:color];
[[tabBarController tabBar] insertSubview:viewa atIndex:0];
[color release];
[viewa release];
[window addSubview:tabBarController.view];
}
Thank you for your help
感谢您的帮助
回答by Gacon
Change source as below, you can fix this problem.
如下更改源,您可以解决此问题。
Old source:
旧来源:
[[tabBarController tabBar] insertSubview:viewa atIndex:0];
New source:
新来源:
//1.Check version of iOS
if(iOSVersion <= 4.3){
[[tabBarController tabBar] insertSubview:viewa atIndex:0];
}else{
//iOS5
[[tabBarController tabBar] insertSubview:viewa atIndex:1];
}
回答by bilbo
Use this code to detect iOS version
使用此代码检测 iOS 版本
if ([[[UIDevice currentDevice] systemVersion] floatValue] < 5) {
[[tabBarController tabBar] insertSubview:viewa atIndex:0];
}else{
[[tabBarController tabBar] insertSubview:viewa atIndex:1];
}
回答by iKushal
// Change the tab bar background
UIImage* tabBarBackground = [UIImage imageNamed:@"tabbar.png"];
[[UITabBar appearance] setBackgroundImage:tabBarBackground];