而不是类别,您应该subclass
UITabBarController
. 这将允许您更好地控制对象。这是一个子类的例子。
// MPCustomTabBar.h
@interface MPCustomTabBar : UITabBarController
- (void) setBackgroundImage:(UIImage *)image;
@end
// MPCustomTabBar.m
@interface MPCustomTabBar
- (void) setBackgroundImage:(UIImage *)image {
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,320,480)];
imageView.backgroundColor = [UIColor colorWithPatternImage:i];
[[self view] addSubview:imageView];
[[self view] sendSubviewToBack:imageView];
[[self view] setOpaque:NO];
[[self view] setBackgroundColor:[UIColor clearColor]];
[imageView release];
}
@end
现在你可以做所有你想要的自定义,分配和初始化你的新子类,如下所示:
MPCustomTabBar *bar = [[MPCustomTabBar alloc] init];