Code Monkey home page Code Monkey logo

xhtabbarswift's Introduction

XHTabBarSwift

一行代码创建自定义TabBar,支持小红点,数字角标及自定义高度

AppVeyor Carthage compatible Version Status Support Pod Platform Pod License

==============

###技术交流群(群号:537476189).

效果

image

使用方法

1.在Appdelegate 中初始化,并设置为根控制器

    /*
    控制器name数组
    */
    let  controllerArray = ["MainVC","MsgVC","FriendVC","MeVC"]
    /*
    title数组
    */
    let  titleArray = ["首页","消息","朋友","我的"]
    /*
    默认图片数组
    */
    let  imageArray = ["home_tabbar","msg_tabbar","friend_tabbar","me_tabbar"]
    /*
    选中图片数组
     */
    let  selImageArray = ["home_tabbar_sel","msg_tabbar_sel","friend_tabbar_sel","me_tabbar_sel"]
    /*
    tabbar高度最小值49.0, 传nil或<49.0均按49.0处理
    */
    let height = CGFloat(49)
        
    /*
    创建tabBarController
    */
    let tabBarController = XHTabBar(controllerArray:controllerArray,titleArray: titleArray,imageArray: imageArray,selImageArray: selImageArray,height:height)

    /*
    设置为根控制器    
    */
    window?.rootViewController = tabBarController

2.影藏tabBar

     /*
     push界面时,影藏tabBar,如下
     */
     let controller = UIViewController.init()
     controller.hidesBottomBarWhenPushed = true
     self.navigationController?.pushViewController(controller, animated: true)

3.角标、小红点及其他设置接口

     /**
     *  手动切换显示到指定控制器
     *
     *  - param: index 位置
     */
    public func showControllerIndex(_ index: Int)
    
    /**
     *  设置数字角标
     *
     *  - param: num   所要显示数字
     *  - param: index 位置
     */
    public func showBadgeMark(_ badge:: Int, index: Int)
        
    /**
     *  设置小红点
     *
     *  - param: index 位置
     */
    public func showPointMarkIndex(_ index: Int)
    
    /**
     *  影藏指定位置角标
     *
     *  - param: index 位置
     */
    public func hideMarkIndex(_ index: Int)

4.定义tabbar文字大小,颜色,请在XHTabBar.m 顶部修改下面值即可

/**
 *  tabbar背景色
 */
private let ColorTabBar = UIColor.white

/**
 *  title默认颜色
 */
private let ColorTitle = UIColor.gray

/**
 *  title选中颜色
 */
private let ColorTitleSel = ColorRGB(41,g: 167,b: 245)

/**
 *  title字体大小
 */
private let titleFontSize : CGFloat = 12.0

/**
 *  数字角标直径
 */
private let numMarkD:CGFloat = 20.0

/**
 *  小红点直径
 */
private let pointMarkD:CGFloat = 12.0

/**
 *  button 图片与文字上下占比
 */
private let scale:CGFloat = 0.55

安装

手动添加:

  • 1.将 XHTabBar 文件夹添加到工程目录中

CocoaPods:

  • 1.在 Podfile 中添加 pod 'XHTabBarSwift'
  • 2.执行 pod install 或 pod update
  • 3.导入 import XHTabBarSwift

Tips

  • 1.如果发现pod search XHTabBarSwift 搜索出来的不是最新版本,需要在终端执行cd desktop退回到desktop,然后执行pod setup命令更新本地spec缓存(需要几分钟),然后再搜索就可以了
  • 2.如果你发现你执行pod install后,导入的不是最新版本,请删除Podfile.lock文件,在执行一次 pod install

注意

  • 该项目通过 动态获取命名空间 + . + 类名 来创建类对象,如下:
let cls: AnyClass? = NSClassFromString(命名空间 + "." + 类名)
  • 实测中发现,当命名空间为非全英文 或含有 - 等特殊字符时 创建类对象会为 nil
  • 1.项目命名空间默认为项目名称.
    2.当碰到类名称正确 创建类对象失败(即报error:cls不能当做UIViewController错误时)时,可以到TARGETS -> Build Settings ->Produce Name 中修改命名空间为全英文,并去掉命名空间中 - 等特殊字符: image

系统要求

  • 该项目最低支持 iOS 8.0 和 Xcode 8.0

许可证

XHTabBarSwift 使用 MIT 许可证,详情见 LICENSE 文件

xhtabbarswift's People

Contributors

coderzhuxh avatar honbolau avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.