• 自定义弧形的 tabBar


    //
    //  TabBarViewController.h
    //  LittleLoveLive
    //
    //  Created by YJ
    //
    //  TabBarViewController.m
    //  LittleLoveLive
    //
    //  Created by YJ on 16/7/16.
    //  Copyright © 2016年 YJ. All rights reserved.
    //
    
    #import "TabBarViewController.h"
    #import "RootNavigationController.h"
    #import "HomeViewController.h"
    #import "LiveViewController.h"
    #import "MeViewController.h"
    @interface TabBarViewController ()
    
    @end
    
    @implementation TabBarViewController
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        [self setupTheLine];
        [self initialControllers];
    
    }
    
    
    //初始化子控制器
    -(void)initialControllers {
        
        [self setupController:[[HomeViewController alloc]init] image:@"icon_home_normal.png" selectedImage:@"icon_home_pressed.png" title:nil];
        [self setupController:[[LiveViewController alloc]init] image:@"icon_live_normal.png" selectedImage:@"icon_live_pressed.png" title:nil];
        [self setupController:[[MeViewController alloc] init] image:@"icon_me_normal.png" selectedImage:@"icon_me_pressed.png" title:nil];
        
    }
    
    //设置控制器
    -(void)setupController:(UIViewController *)childVc image:(NSString *)image selectedImage:(NSString *)selectedImage title:(NSString *)title {
        
        //标题
        childVc.title = title;
        //childVc.view.backgroundColor = RGBACOLOR(239.0f, 239.0f, 244.0f, 1.0f);
        
        //tabBarItem图片
        childVc.tabBarItem.image = [[UIImage imageNamed:image] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        childVc.tabBarItem.selectedImage = [[UIImage imageNamed:selectedImage]imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        
        
        //tabBarItem字体的设置
        //正常状态
        NSMutableDictionary *normalText = [NSMutableDictionary dictionary];
        normalText[NSForegroundColorAttributeName] = [UIColor colorWithRed:123/255.0 green:123/255.0 blue:123/255.0 alpha:1.0];
        [childVc.tabBarItem setTitleTextAttributes:normalText forState:UIControlStateNormal];
        
        //选中状态
        NSMutableDictionary *selectedText = [NSMutableDictionary dictionary];
        selectedText[NSForegroundColorAttributeName] = [UIColor blackColor];
        [childVc.tabBarItem setTitleTextAttributes:selectedText forState:UIControlStateSelected];
        
        RootNavigationController *nav = [[RootNavigationController alloc]initWithRootViewController:childVc];
        [self addChildViewController:nav];
        
    }
    
    //设置分割线
    -(void)setupTheLine {
    
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(0, -8, self.tabBar.frame.size.width, self.tabBar.frame.size.height)];
        [imageView setImage:[UIImage imageNamed:@"bg_tabbar"]];
        [imageView setContentMode:UIViewContentModeCenter];
        [self.tabBar insertSubview:imageView atIndex:0];
        //覆盖原生Tabbar的上横线
        [[UITabBar appearance] setShadowImage:[self createImageWithColor:[UIColor clearColor]]];
        [[UITabBar appearance] setBackgroundImage:[self createImageWithColor:[UIColor clearColor]]];
        //设置TintColor
        //    UITabBar.appearance.tintColor = [UIColor orangeColor];
        
    }
    
    -(UIImage*) createImageWithColor:(UIColor*) color
    {
        CGRect rect=CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
        UIGraphicsBeginImageContext(rect.size);
        CGContextRef context = UIGraphicsGetCurrentContext();
        CGContextSetFillColorWithColor(context, [color CGColor]);
        CGContextFillRect(context, rect);
        UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return theImage;
    }
    
    
    //设置中间按钮不受TintColor影响
    - (void)awakeFromNib {
        [super awakeFromNib];
        NSArray *items =  self.tabBar.items;
        //设置第几个 tabBar不受影响
        UITabBarItem *btnAdd = items[1];
        btnAdd.image = [btnAdd.image imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        btnAdd.selectedImage = [btnAdd.selectedImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    
    
    
    @end
    
    
    
     on 16/7/16.
    //  Copyright © 2016年 YJ. All rights reserved.
    //
    
    #import <UIKit/UIKit.h>
    
    @interface TabBarViewController : UITabBarController
    
    @end
  • 相关阅读:
    财务高手-资本高手
    做到顶尖看三种书-大牛的书 工具书 教材书
    拓端tecdat|R语言使用HAR-RV预测实际波动率Realized Volatility案例
    拓端tecdat|WINBUGS对随机波动率模型进行贝叶斯估计与比较
    拓端tecdat|R语言机器学习实战之多项式回归
    拓端tecdat|R语言风险价值VaR(Value at Risk)和损失期望值ES(Expected shortfall)的估计
    拓端tecdat|TensorFlow 2.0 keras开发深度学习模型实例:多层感知器(MLP),卷积神经网络(CNN)和递归神经网络(RNN)
    拓端tecdat|Python安装TensorFlow 2、tf.keras和深度学习模型的定义
    cookie绕过验证码登录
    [转]Python3 字典 items() 方法
  • 原文地址:https://www.cnblogs.com/ningmengcao-ios/p/5728007.html
Copyright © 2020-2023  润新知