.h文件:
#import@interface YLYTabBar : UIView@end
.m文件
#import "YLYTabBar.h"@implementation YLYTabBar- (id)initWithFrame:(CGRect)frame{ self = [super initWithFrame:frame]; if (self) { // 1.设置背景色 self.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageWithNamed:@"tabbar_background"]]; } return self;}
使用:
-(void)addTabBar{ YLYTabBar *myTabBar = [[YLYTabBar alloc] init]; myTabBar.frame = self.tabBar.bounds; [self.tabBar addSubview:myTabBar];}-(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; //移除之前的4各UITabBarButton for (UIView *child in self.tabBar.subviews) { if ([child isKindOfClass:[UIControl class]]) { [child removeFromSuperview]; } }}