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
  • 相关阅读:
    thinkphp3.2新部署是错
    淘宝code
    面试感悟----一名3年工作经验的程序员应该具备的技能---转载
    【海量之道】海量之道之SET模型
    看过年人流高峰,浅聊并发之战[架构篇]
    docker启动遇到的问题
    监听数据配置
    Python+requests+unittest+excel实现接口自动化测试框架
    冒泡排序及优化
    jmeter监控的一些插件
  • 原文地址:https://www.cnblogs.com/goodboy-heyang/p/4694391.html
Copyright © 2011-2022 走看看