MCTabBarController
- 自定义 tabBarController 的一种简单方法
- 详情 简书
将 MCTabBarController 添加到您的项目中
CocoaPods
CocoaPods 是将 MCTabBarController 添加到您项目中的推荐方式。
- 1、在 Podfile 中添加 MCTabBarController 的 pod 条目
pod 'MCTabBarController'
- 2、通过运行 pod install 命令安装 pod。
- 3、在需要的地方包含 MCTabBarController,使用 #import "MCTabBarController.h".
源文件
或者您可以直接将 MCTabBarController 文件夹添加到您的项目中。
- 1、下载最新的代码版本或将存储库作为 git 子模块添加到您的 git-tracked 项目中。
- 2、在 Xcode 中打开您的项目,然后将 MCTabBarController 文件夹拖到您的项目上(使用“Product Navigator 视图”)。如果代码归档是从项目外提取的,确保在询问时选择 Copy items。
- 3、在需要的地方包含 MCTabBarController,使用 #import "MCTabBarController.h".
需求
- Xcode 8及更高版本
- iOS 8.0及更高版本
截图
用法
创建你的类,使其继承自 MCTabBarController 类
#import "MCTabBarController.h"
@interface NormalTabBarController : MCTabBarController
@end
@interface NormalTabBarController ()
@end
@implementation NormalTabBarController
- (void)viewDidLoad {
[super viewDidLoad];
//选中时的颜色
// self.mcTabbar.tintColor = [UIColor colorWithRed:27.0/255.0 green:118.0/255.0 blue:208/255.0 alpha:1];
//透明设置为NO,显示白色,view的高度到tabbar顶部截止,YES的话到底部
self.mcTabbar.translucent = NO;
self.mcTabbar.centerImage = [UIImage imageNamed:@"tab_unselect_gray"];
self.mcTabbar.centerSelectedImage = [UIImage imageNamed:@"tab_select_blue"];
// 可设置宽高
// self.mcTabbar.centerWidth = 40;
// self.mcTabbar.centerHeight = 40;
[self addChildViewControllers];
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
//添加子控制器
- (void)addChildViewControllers{
//图片大小建议32*32
[self addChildrenViewController:[[ViewController alloc] init] andTitle:@"首页" andImageName:@"tab1"];
//中间这个不设置东西,只占位
[self addChildrenViewController:[[ViewController alloc] init] andTitle:@"" andImageName:@""];
[self addChildrenViewController:[[ViewController alloc] init] andTitle:@"发现" andImageName:@"tab3"];
}
- (void)addChildrenViewController:(UIViewController *)childVC andTitle:(NSString *)title andImageName:(NSString *)imageName{
childVC.tabBarItem.image = [UIImage imageNamed:imageName];
// 选中的颜色由tabbar的tintColor决定
childVC.tabBarItem.selectedImage = [UIImage imageNamed:imageName];
childVC.title = title;
BaseNavigationController *baseNav = [[BaseNavigationController alloc] initWithRootViewController:childVC];
[self addChildViewController:baseNav];
}
//... something
许可协议
本代码根据MIT许可证的条款和条件分发。
联系
如果你发现bug,请向我pull reqeust,如果你觉得对我有所帮助,请给个star吧