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
  • 相关阅读:
    php小结
    HTML-WEB前端-photoshop切图抠图详解
    JS面向对象的程序设计
    AJAX同步与异步的区别
    数据库的优化
    phpcms网站搬家 至 服务器 完整并且详细过程
    phpcms网页替换验证码功能 及 搜索功能
    用phpcms切换中英文网页的方法(不用解析二级域名)、phpcms完成pc和手机端切换(同一域名)
    JS常用屏蔽代码
    信息安全政策(隔离与监控)
  • 原文地址:https://www.cnblogs.com/goodboy-heyang/p/4694391.html
Copyright © 2011-2022 走看看