//设置背景颜色
#import "ILTabBar.h"
@implementation ILTabBar
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
-(id)initWithFrame:(CGRect)frame{
self=[super initWithFrame:frame];
if(self){
//设置背景颜色
self.backgroundColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"TabBarBack"]];
}
return self;
}
@end
方法二与方法三效果上有区别
删除系统自带的按钮
#import "ILTabBarButton.h"
#import "ILTabBar.h"
@implementation ILTabBarButton
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
// Drawing code
}
*/
-(void) viewDidLoad{
[super viewDidLoad];
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
//1.删除默认的tab按钮
//--------删除按钮方法1
[self.tabBar removeFromSuperview];
//--------删除按钮方法2
// for (UIControl *btn in self.tabBar.subviews) {
// [btn removeFromSuperview];
// }
//2.设置tabbar的背景
// self.tabBar.backgroundImage=[UIImage imageNamed:@"TabBarBack"];
//-----------分割线设置背景方法2
// UITabBar *tabbar=[UITabBar appearance];
// [tabbar setBackgroundImage:[UIImage imageNamed:@"TabBarBack"]];
//----------分割线设置背景方法3
//2.创建tabbar
ILTabBar *mytabbar=[[ILTabBar alloc]init];
mytabbar.frame=self.tabBar.frame;
[self.view addSubview:mytabbar];
});
}
@end