改变UITabBar的色调/背景颜色

UINavigationBar和UISearchBar都有一个tintColor属性,允许你改变这两个项目的色调(我知道)。我想在我的应用程序中对UITabBar做同样的事情,但现在已经找到了从默认的黑色中改变它的方法。有任何想法吗?



www说
浏览 1024回答 3
3回答

拉风的咖菲猫

我已经能够通过子类化UITabBarController并使用私有类来使其工作:@interface UITabBarController (private)- (UITabBar *)tabBar;@end@implementation CustomUITabBarController- (void)viewDidLoad {    [super viewDidLoad];    CGRect frame = CGRectMake(0.0, 0.0, self.view.bounds.size.width, 48);    UIView *v = [[UIView alloc] initWithFrame:frame];    [v setBackgroundColor:kMainColor];    [v setAlpha:0.5];    [[self tabBar] addSubview:v];    [v release];}@end

翻过高山走不出你

我有一个最终答案的附录。虽然基本方案是正确的,但可以改进使用部分透明颜色的技巧。我假设它只是让默认渐变显示出来。哦,同样,TabBar的高度是49像素而不是48像素,至少在OS 3中是这样。因此,如果你有一个带有渐变的适当的1 x 49图像,这是你应该使用的viewDidLoad的版本:- (void)viewDidLoad {    [super viewDidLoad];     CGRect frame = CGRectMake(0, 0, 480, 49);    UIView *v = [[UIView alloc] initWithFrame:frame];    UIImage *i = [UIImage imageNamed:@"GO-21-TabBarColorx49.png"];    UIColor *c = [[UIColor alloc] initWithPatternImage:i];    v.backgroundColor = c;    [c release];    [[self tabBar] addSubview:v];    [v release];}
打开App,查看更多内容
随时随地看视频慕课网APP