Reputation: 31
Would like to set a custom background for my selected tabs, thus far, subclassing is they way I'm customizing the UITAbBar/UITabBarItem.
The question is: Does anybody know (or know where I could find ) what the property is that sets the background?
There is a lighter black/grey rounded box around the selected tab. That is what I'm aiming at changing.
iOS 4.1 ships with Game Center, and they've completely customized the UITabBar. I'm looking to do something similar.
Upvotes: 3
Views: 1634
Reputation: 27224
In order to achieve the above you are going to need to create a custom UITabBarController
class.
CustomUITabBarController.h
#import <UIKit/UIKit.h>
@interface CustomUITabBarController: UITabBarController {
IBOutlet UITabBar *tabBar1;
}
@property (nonatomic, retain) UITabBar *tabBar1;
@end
CustomUITabBarController.m
#import “CustomUITabBarController.h”
@implementation CustomUITabBarController
@synthesize tabBar1;
- (void)viewDidLoad {
[super viewDidLoad];
tabBar1.backgroundColor = [UIColor clearColor];
CGRect frame = CGRectMake(0, 0, 480, 49);
UIView *v = [[UIView alloc] initWithFrame:frame];
UIImage *i = [UIImage imageNamed:@"customImage.png"];
UIColor *c = [[UIColor alloc] initWithPatternImage:i];
v.backgroundColor = c;
[c release];
[[self tabBar] insertSubview:v atIndex:0];
[v release];
}
@end
You'll then need to change MainWindow.xib and choose the Tab Bar Controller. Within the Property inspector you need to change the class to your custom class, then associate the tabBar1
outlet to the Tab Bar Controller.
Upvotes: 1