gpt4 book ai didi

iphone - 自定义 TabBar 颜色 iOS 5.0.1

转载 作者:行者123 更新时间:2023-11-28 17:40:03 24 4
gpt4 key购买 nike

我想使用自定义的 TabBar 颜色。

在 iOS 5 发布之后,我使用了以下代码:

CGRect frame = CGRectMake(0, 0, 480, 49);
UIView *view = [[UIView alloc] initWithFrame:frame];
UIImage *tabBarBG = [UIImage imageNamed:@"tabBar.png"];
UIColor *color = [[UIColor alloc] initWithPatternImage:tabBarBG];
[view setBackgroundColor:color];
[color release];

if ([[[UIDevice currentDevice] systemVersion] floatValue] > 4.9) {

[self.tabBarController.tabBar insertSubview:view atIndex:1];
}
else {

[self.tabBarController.tabBar insertSubview:view atIndex:0];
}

[view release];

在 iOS 5 中可以,但在 iOS 5.0.1 中不起作用。

如何在 iOS 5.0.1 中设置 TabBar 颜色?

谢谢

最佳答案

由于新的外观 API,您不再需要在 iOS5 中使用该技巧。您可以在 iOS 5 的标签栏上设置 backgroundImage 和 tintColor 等属性,所以只需执行以下操作:

if ([self.tabBarController.tabBar respondsToSelect:@selector(setBackgroundImage:)])
{
self.tabBarController.tabBar.backgroundImage = someImage;
}
else
{
//use the old iOS4 subview hack
}

关于iphone - 自定义 TabBar 颜色 iOS 5.0.1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8544850/

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