新建一个类继承UITabBarController:
- (id) init
{
self = [super init];
if (self) {
//方法一
UIImageView *img = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"bg.png"]];
img.frame = CGRectMake(0, 0, self.tabBar.frame.size.width, self.tabBar.frame.size.height);
img.contentMode = UIViewContentModeScaleToFill;
//img.frame = CGRectOffset(img.frame, 0, 1);
[[self tabBar] insertSubview:img atIndex:0];
[img release];
//方法二
CGRect frame = CGRectMake(0, 0, self.view.bounds.size.width, 49);
UIView *view = [[UIView alloc] initWithFrame:frame];
UIImage *tabBarBackgroundImage = [UIImage imageNamed:@"bg.png"];
UIColor *color = [[UIColor alloc] initWithPatternImage:tabBarBackgroundImage];
[view setBackgroundColor:color];
[color release];
[[self tabBar] insertSubview:view atIndex:0];
[view release];
}
return self;
}