MCTabBarControllerSwift 版本 1.0.2

MCTabBarControllerSwift 版本 1.0.2

‘Calary’ 维护。



  • 作者
  • Ccalary

MCTabBarController

  • 自定义 tabBarController 的简单方法
  • 详细 简书

将 MCTabBarController 添加到您的项目中

CocoaPods

CocoaPods 是将 MCTabBarController 添加到项目的推荐方式。

  • 1、在 Podfile 中为 MCTabBarController 添加 pod

pod 'MCTabBarController'

  • 2、通过运行 pod install 来安装 pod。
  • 3、使用 #import "MCTabBarController.h" 在需要位置引入 MCTabBarController。

源文件

或者您可以直接将 MCTabBarController 文件夹添加到您的项目中。

  • 1、下载最新的代码版本或将存储库作为 git 子模块添加到您的 git-tracked 项目中。
  • 2、在 Xcode 中打开您的项目,然后从项目导航器视图中将 MCTabBarController 文件夹拖动到您的项目(如果代码存档是从项目外提取的,则在询问时选择复制项目)。
  • 3、使用 #import "MCTabBarController.h" 在需要位置引入 MCTabBarController。

需求

  • Xcode 8 或更高版本
  • iOS 8.0 或更高版本

截图

screenShot

用法

创建你的类,使其继承自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,请给我拉取请求,如果你觉得对你有所帮助,请给我点个star🌟