Reputation: 1
I have made an iPhone application in Xcode 4.2 and snow leopard in which I have set the navigation bar and tab bar background color by implementing following code
CGRect frame = CGRectMake(0.0, 0.0, self.view.bounds.size.width, 48);
UIView *v = [[UIView alloc] initWithFrame:frame];
[v setBackgroundColor:[UIColor colorWithRed:1.0f/255.0f green:140.0f/255.0f
blue:131.0f/255.0f alpha:1.0f]];
[[self.tabBarController tabBar] insertSubview:v atIndex:0];
[v release];
self.navigationController.navigationBar.tintColor = [UIColor colorWithRed:1.0f/255.0f
green:125.0f/255.0f blue:131.0f/255.0f alpha:1.0f];
it is working fine but now if I am running this app in ios 5 and xcode 4.2 , navigation bar color set but tabbar background color doesn't set
How can I set background color of tabbar in ios 5? If someone know please help me.
Thanks alot.
Upvotes: 0
Views: 4012
Reputation: 707
CGRect frame = CGRectMake(0.0, 0.0, 320, 48);//Setting a Frame.
myTabView = [[UIView alloc] initWithFrame:frame];//Making Tab View
// not supported on iOS4
UITabBar *tabBarr = [self.tabBar tabBar];
if ([tabBarr respondsToSelector:@selector(setBackgroundImage:)])
{
// set it just for this instance
[tabBarr setBackgroundImage:[UIImage imageNamed:@"hot-1.png"]];
// set for all
// [[UITabBar appearance] setBackgroundImage: ...
}
else
{
// ios 4 code here
//[tabBarr setBackgroundColor:c];
}
//[myTabView setBackgroundColor:c];//Setting Color Of TaBar.
[myTabView setAlpha:0.8];//Setting Alpha of TabView.
[[self.tabBar tabBar] insertSubview:myTabView atIndex:0];//Inserting Tab As SubView.
Use this instead of setting color to background of tabbar ....
Upvotes: 2