首先封装一个button,拥有UITabbarItem的属性item
封装一个继承于UIView的CustomTabbar,initWithframe方法中设置好中间的+号,写添加button的方法,并声明点击点击button的协议方法
- (void)tabBar:(CustomTabBar *)tabBar didselectedFrom:(NSInteger)from to:(NSInteger)to;
添加button的方法
- (void)addbuttonWithTabBarItem:(UITabBarItem *) item
{
CustomButton *button = [[CustomButton alloc] init];
button.item = item;
[button addTarget:self action:@selector(buttonClick:) forControlEvents:UIControlEventTouchDown];
// 这里没有设置位置,会在flowLayout方法中根据button的数量进行动态设置
[self addSubview:button];
[self.customButtons addObject:button];
if (self.customButtons.count == 1) {
[self buttonClick:button];
}
}
封装继承于UITabBarController的TabBarViewController类,其中将CustomTabBar作为属性,设置customTabbar的代理实现其协议方法这样就能实现点击不同button跳转到不懂页面,移除系统自带tabbar上的控件,添加customtabbar,