newton_guima
newton_guima

Reputation: 1569

TabBar customization in ios4 doesnt work in ios5

In my app i want to customize the pattern of the tabbar, but my deployment target is ios4, so i am using the code bellow in the appDidBecomeActive in the appDelegate.m to do this:

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];

When i run the app using the 4.3 simulator, it works properly, but when i simulate in ios5, it doesnt work, the tab goes back to black.. any help?

Thanks.

Upvotes: 1

Views: 881

Answers (1)

Vladimir
Vladimir

Reputation: 170839

in iOS 5 there's new backgroundImage property in UITabBar class and you should use it:

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];
}

Upvotes: 1

Related Questions