将自定义的button和label 添加到原有的Tabbar上 这样不需再考虑push时如何隐藏的问题,只要使用系统隐藏方法
首先看一下效果图 这种效果的实现 只需要首页 分类 发现我的 灰色切图一组,桔色切图一组,和拍摄按钮切图 白色背景不需切图 可用控件实现,如果UI给的切图有带弧边的白色背景图 并不需要使用它 如果使用背景图来实现 对于不同屏幕尺寸的适应会比较麻烦,容易变形。
效果图
1. 创建我的
MyTabBarViewController 继承于UITabBarController
.h文件中
#import <UIKit/UIKit.h>
@interface MyTabBarViewController :UITabBarController
// 创建自定义的tabbarView
@property (nonatomic,strong)UIView *tabbarView;
// 创建自定义Tabbar的几个按钮和标题label
@property (nonatomic,strong)UIButton *findButton;
@property (nonatomic,strong)UIButton *lanMuButton;
@property (nonatomic,strong)UIButton *huodongButton;
@property (nonatomic,strong)UIButton *wodeButton;
@property (nonatomic,strong)UILabel *findLabel;
@property (nonatomic,strong)UILabel *lanmuLabel;
@property (nonatomic,strong)UILabel *huodonglabel;
@property (nonatomic,strong)UILabel *wodeLabel;
@end
2. .m文件中的相关处理 创建控件 关联tabbar等//
- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [superinitWithNibName:nibNameOrNilbundle:nibBundleOrNil];
if (self) {
self.tabBar.translucent = NO;
}
returnself;
}
- (void)viewDidLoad {
[superviewDidLoad];
[selfcreateView];
[selfcreateTabbarView];
}
- (void)createView{
设置tag值 与按钮点击关联
//发现
FindViewController *findVc = [[FindViewControlleralloc]init];
FLGNanViewController *findNaVC = [[FLGNanViewControlleralloc]initWithRootViewController:findVc];
findVc.tabBarItem.tag =1000;
//栏目
ClassifyViewController *lanmuvc = [[ClassifyViewControlleralloc]init];
FLGNanViewController *lanmuNavc = [[FLGNanViewControlleralloc]initWithRootViewController:lanmuvc];
lanmuvc.tabBarItem.tag =2000;
//相机
UIViewController *view = [[UIViewControlleralloc]init];
//活动
HuoDongViewController *hudongVC = [[HuoDongViewControlleralloc]init];
FLGNanViewController *huoDongNavic = [[FLGNanViewControlleralloc]initWithRootViewController:hudongVC];
hudongVC.tabBarItem.tag =3000;
//我的
WodeViewController *wodeVc = [[WodeViewControlleralloc]init];
FLGNanViewController *wodeNaVC = [[FLGNanViewControlleralloc]initWithRootViewController:wodeVc];
wodeVc.tabBarItem.tag =4000;
//
self.viewControllers = [NSArrayarrayWithObjects:findNaVC, lanmuNavc,view, huoDongNavic, wodeNaVC,nil];
}
- (void)createTabbarView{
// 创建TabbarView 添加到系统Tabbar
self.tabbarView = [[UIViewalloc]initWithFrame:CGRectMake(0, -15,self.view.frame.size.width,64)];
self.tabbarView.backgroundColor = [UIColorwhiteColor];
[self.tabBaraddSubview:self.tabbarView];
// 设置TabbarView 阴影效果