gpt4 book ai didi

ios - ios4 中的 TabBar 自定义在 ios5 中不起作用

转载 作者:行者123 更新时间:2023-11-29 13:43:50 25 4
gpt4 key购买 nike

在我的应用程序中,我想自定义标签栏的模式,但我的部署目标是 ios4,所以我在 appDelegate.m 的 appDidBecomeActive 中使用下面的代码来执行此操作:

CGRect frameTab = CGRectMake(0, 0, 480, 49);
UIView *viewTab = [[UIView alloc]initWithFrame:frameTab];
UIImage *tabBarBackground = [UIImage imageNamed:@"tab_bar.png"];
UIColor *tabColor = [[UIColor alloc]initWithPatternImage:tabBarBackground];
[viewTab setBackgroundColor:tabColor];
[[myTabBarController tabBar] insertSubview:viewTab atIndex:0];

当我使用 4.3 模拟器运行应用程序时,它可以正常工作,但是当我在 ios5 中模拟时,它不起作用,选项卡变回黑色。有什么帮助吗?

谢谢。

最佳答案

在 iOS 5 中,UITabBar 类中有新的 backgroundImage 属性,您应该使用它:

UIImage *tabBarBackground = [UIImage imageNamed:@"tab_bar.png"];
if ([[myTabBarController tabBar] respondsToSelector:@selector(setBackgroundImage:)]){
[[myTabBarController tabBar] setBackgroundImage: tabBarBackground];
}
else{
// If no backgroundImage property (pre iOS5) use your old code
CGRect frameTab = CGRectMake(0, 0, 480, 49);
UIView *viewTab = [[UIView alloc]initWithFrame:frameTab];
UIColor *tabColor = [[UIColor alloc]initWithPatternImage:tabBarBackground];
[viewTab setBackgroundColor:tabColor];
[[myTabBarController tabBar] insertSubview:viewTab atIndex:0];
}

关于ios - ios4 中的 TabBar 自定义在 ios5 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8243006/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com