【发布时间】:2012-01-18 15:45:40
【问题描述】:
我有以下代码在我的标签栏背景中放置了一个漂亮的图像,但它停止工作。有没有人对我能做什么有任何其他建议。我尝试了其他一些选项,如下所示:Setting a background image for a tabbar
-(void)viewDidLoad
{
CGRect frame = CGRectMake(0, 0, 480, 49);
UIView *v = [[UIView alloc] initWithFrame:frame];
UIImage *i = [UIImage imageNamed:@"smallMenuBackground.png"];
UIColor *c = [[UIColor alloc] initWithPatternImage:i];
v.backgroundColor = c;
[c release];
[mainTabBar insertSubview:v atIndex:0];
[v release];
[super viewDidLoad];
}
任何帮助表示赞赏。
2012 年 1 月 23 日更新
好的,我已经取得了一些进展。自从我升级到 Xcode 4.2 和 IOS5 后,这才停止工作。我设法使用 Interface Builder 中的选项将其取回,但现在它仅适用于 IOS5。理想情况下,我希望以编程方式开始工作,但我现在会满足于 IB 解决方案。
我似乎无法让它适用于任何以前的版本。
注意:我的 TabBar 仅在我的 rootviewcontroller 上,没有其他屏幕。
问候,斯蒂芬
【问题讨论】:
-
在图像颜色设置之前添加行 self.view.backgroundColor = [UIColor clearColor];
-
阿米特,这会清除主视图的背景颜色。它是我感兴趣的标签栏。
-
我相信 Apple 可能已经改变了 iOS 5.0.1 中标签栏的内部视图布局(或者故意破坏了这个技巧),因为其他一些人一直在报告同样的问题。答案是切换到使用官方外观 API 函数(见下面我的回答)。