zoukankan      html  css  js  c++  java
  • IOS开发之功能模块--自定义UITabBarViewController的备用代码

    前言:因为常用,所以我就备份到这里,然后如果需要修改,可以根据需求进行相关的更改。

     1 @implementation YMTabBarController
     2 
     3 - (void)viewDidLoad {
     4     [super viewDidLoad];
     5     /**** 初始化一些设置 ****/
     6     [self setUp];
     7     
     8     /**** 添加子控制器 ****/
     9     [self addChildViewControllers];
    10 }
    11 - (void)setUp{
    12     
    13 }
    14 
    15 #pragma mark - 在load方法里全局设置所有UITabBarItem的文字属性
    16 // hy:配置全局设置属性
    17 + (void)load
    18 {
    19 //    UITabBarItem *item = [UITabBarItem appearanceWhenContainedIn:self, nil];
    20     // 普通状态下的文字属性
    21 //    NSMutableDictionary *normalAttrs = [NSMutableDictionary dictionary];
    22 //    normalAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    23 //    normalAttrs[NSForegroundColorAttributeName] = [UIColor colorWithHexString:@"#333333"];
    24 //    [item setTitleTextAttributes:normalAttrs forState:UIControlStateNormal];
    25     // 选中状态下的文字属性
    26 //    NSMutableDictionary *selectedAttrs = [NSMutableDictionary dictionary];
    27 //    selectedAttrs[NSFontAttributeName] = [UIFont systemFontOfSize:12];
    28 //    selectedAttrs[NSForegroundColorAttributeName] = [UIColor colorWithHexString:@"#23ac3a"];
    29 //    [item setTitleTextAttributes:selectedAttrs forState:UIControlStateSelected];
    30 }
    31 
    32 #pragma mark - 添加 导航控制器+子控制器
    33 - (void)addChildViewControllers{
    34     // 首页
    35     [self setupOneChildViewController:[[MainViewController alloc] init] title:@"首页" image:@"" selectedImage:@""];
    36     
    37     // 我的
    38     [self setupOneChildViewController:[[MineViewController alloc] init] title:@"我的" image:@"" selectedImage:@""];
    39 }
    40 
    41 #pragma mark - 私有方法
    42 /**
    43  *  初始化一个子控制器
    44  *
    45  *  @param vc            子控制器
    46  *  @param title         标题
    47  *  @param image         图标
    48  *  @param selectedImage 选中的图标
    49  */
    50 - (void)setupOneChildViewController:(UIViewController *)vc title:(NSString *)title image:(NSString *)image selectedImage:(NSString *)selectedImage
    51 {
    52     YMNavigationController *nc = [[YMNavigationController alloc] initWithRootViewController:vc];
    53     // 设置导航控制器的标题
    54 //    vc.navigationItem.title = title;
    55     // 设置tabBarItem的表诶
    56     nc.tabBarItem.title = title;
    57     if (image.length) { // 图片名有具体值
    58         nc.tabBarItem.image = [UIImage imageRenderingModeImageNamed:image];
    59         nc.tabBarItem.selectedImage = [UIImage imageRenderingModeImageNamed:selectedImage];
    60     }
    61     [self addChildViewController:nc];
    62 }
    63 
    64 @end
  • 相关阅读:
    leetcode 111二叉树的最小深度
    leetcode 104. 二叉树的最大深度
    React简介,开发环境搭建,项目结构目录
    词典中最长的单词
    React export和export default的区别
    哈希表-两个数组的交集
    BFS-地图分析&岛屿数量
    js 下拉框实现去重 & layui可输入可搜索的下拉框
    BFS(找最短距离,最短路径)二叉树最小深度&打开转盘锁&对称二叉树
    python操作es增删改查
  • 原文地址:https://www.cnblogs.com/goodboy-heyang/p/4694391.html
Copyright © 2011-2022 走看看