How to create tabbar with ESTabBarController in swift 3.0

How to create tabbar with ESTabBarController in swift 3.0

First Install CocoaPods
  1. Open terminal and cd ~ to your project directory
  2. Run the command - pod init
  3. Your podfile should be use with - pod "ESTabBarController-swift" and save it
  4. And install it with command pod install
Open project file of .xcworkspace extension
  1. In project we need to add Content all swift class and pop.framework
  2. Don't add pop.framework using add File to. you must be add from Framework and add Others.
  3. In Content folder's all file import ESTabBarController_swift
StoryBord Stuff

Add navigation Controller ane also add ExampleNavigationController from the example code of EST demo. (You can add your own too) but make sure you set its Class of navigation custom swift class.
Code Stuff at AppDelegate.swift

You need to do following code AppDelegate.swift
//
//  AppDelegate.swift
//  DNApp
//
//  Created by 雷神 on 2017/9/6.
//  Copyright © 2017年 aider.cc. All rights reserved.
//

import UIKit
import CoreData
import ESTabBarController_swift

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate,UITabBarControllerDelegate {

    
    var window: UIWindow?
    
    
    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        
        let tabBarController = ESTabBarController()
        tabBarController.delegate = self
        tabBarController.title = "Irregularity"
        tabBarController.tabBar.shadowImage = UIImage(named: "transparent")
        tabBarController.tabBar.backgroundImage = UIImage(named: "background_dark")
        tabBarController.shouldHijackHandler = {
            tabbarController, viewController, index in
            if index == 2 {
                return true
            }
            return false
        }
        tabBarController.didHijackHandler = {
            [weak tabBarController] tabbarController, viewController, index in
            
            DispatchQueue.main.asyncAfter(deadline: .now() + 0.2) {
                let alertController = UIAlertController.init(title: nil, message: nil, preferredStyle: .actionSheet)
                let takePhotoAction = UIAlertAction(title: "Take a photo", style: .default, handler: nil)
                alertController.addAction(takePhotoAction)
                let selectFromAlbumAction = UIAlertAction(title: "Select from album", style: .default, handler: nil)
                alertController.addAction(selectFromAlbumAction)
                let cancelAction = UIAlertAction(title: "Cancel", style: .cancel, handler: nil)
                alertController.addAction(cancelAction)
                tabBarController?.present(alertController, animated: true, completion: nil)
            }
        }

        let v1 = ExampleViewController()
        let v2 = ExampleViewController()
        let v3 = ExampleViewController()
        let v4 = ExampleViewController()
        let v5 = ExampleViewController()
        v1.tabBarItem = ESTabBarItem.init(ExampleBouncesContentView(), title: "Home", image: UIImage(named: "home"), selectedImage: UIImage(named: "home_1"))
        v2.tabBarItem = ESTabBarItem.init(ExampleBouncesContentView(), title: "Find", image: UIImage(named: "find"), selectedImage: UIImage(named: "find_1"))
        v3.tabBarItem = ESTabBarItem.init(ExampleBouncesContentView(), title: "Photo", image: UIImage(named: "photo"), selectedImage: UIImage(named: "photo_1"))
        v4.tabBarItem = ESTabBarItem.init(ExampleBouncesContentView(), title: "Favor", image: UIImage(named: "favor"), selectedImage: UIImage(named: "favor_1"))
        v5.tabBarItem = ESTabBarItem.init(ExampleBouncesContentView(), title: "Me", image: UIImage(named: "me"), selectedImage: UIImage(named: "me_1"))
        
        tabBarController.viewControllers = [v1, v2, v3, v4, v5]

        let navigationController = ExampleNavigationController.init(rootViewController: tabBarController)
        tabBarController.title = "Example"
        
        
        self.window?.rootViewController = navigationController

        return true
    }
    
    func applicationWillResignActive(_ application: UIApplication) {
        // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
        // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
    }
    
    func applicationDidEnterBackground(_ application: UIApplication) {
        // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
        // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
    }
    
    func applicationWillEnterForeground(_ application: UIApplication) {
        // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
    }
    
    func applicationDidBecomeActive(_ application: UIApplication) {
        // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
    }
    
    func applicationWillTerminate(_ application: UIApplication) {
        // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
        // Saves changes in the application's managed object context before the application terminates.
        self.saveContext()
    }
    
    // MARK: - Core Data stack
    
    lazy var persistentContainer: NSPersistentContainer = {
        /*
         The persistent container for the application. This implementation
         creates and returns a container, having loaded the store for the
         application to it. This property is optional since there are legitimate
         error conditions that could cause the creation of the store to fail.
         */
        let container = NSPersistentContainer(name: "DNApp")
        container.loadPersistentStores(completionHandler: { (storeDescription, error) in
            if let error = error as NSError? {
                // Replace this implementation with code to handle the error appropriately.
                // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
                
                /*
                 Typical reasons for an error here include:
                 * The parent directory does not exist, cannot be created, or disallows writing.
                 * The persistent store is not accessible, due to permissions or data protection when the device is locked.
                 * The device is out of space.
                 * The store could not be migrated to the current model version.
                 Check the error message to determine what the actual problem was.
                 */
                fatalError("Unresolved error \(error), \(error.userInfo)")
            }
        })
        return container
    }()
    
    // MARK: - Core Data Saving support
    
    func saveContext () {
        let context = persistentContainer.viewContext
        if context.hasChanges {
            do {
                try context.save()
            } catch {
                // Replace this implementation with code to handle the error appropriately.
                // fatalError() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
                let nserror = error as NSError
                fatalError("Unresolved error \(nserror), \(nserror.userInfo)")
            }
        }
    }
    
}

ESTabBarController 是一个高度自定义的 TabBarController 组件,继承自 UITabBarController,可轻松自定义 UI 样式,添加动画等。功能1、支持默认样式如果直接使用ESTabBarController进行初始化,你会得到与UITabBarController完全相同的仿系统样式UITabBarController样式:ESTabBarController仿系统样式:2、支持带有"More"的默认样式使用ESTabBarController进行初始化,若item大于最大显示数量则显示"More",样式与UITabBarController一致带有"More"的UITabBarController样式:带有"More"的ESTabBarController样式:3、支持UITabBarItem和ESTabBarItem混合可以任意设置tabbar的items,支持即包含UITabBarItem,同时也包含ESTabBarItemESTabBar和UITabBar混合样式:带有'More'的ESTabBar和UITabBar混合样式:4、支持UIKit属性支持UITabBarController、UITabBar和UITabBarItem的大部分api属性,使原有代码无需任何修改即可无缝迁移到ESTabBarController支持UITabBarController的selectedIndex属性的实现:5、支持与UINavigationController任意嵌套通常在使用UITabBarController过程中,会存在两种比较常见的层级处理方式:第一种:├── UITabBarController└──── UINavigationController└────── UIViewController└──────── SubviewControllers第二种:├── UINavigationController└──── UITabBarController└────── UIViewController└──────── SubviewControllers第一种情况在push子视图的时候需要设置 hidesBottomBarWhenPushed = true , 第二种则不需要在ESTabBarController中,通过添加Container视图到UITabBar的方式来兼容这两种层级处理方式。6、支持自定义使用ESTabBarController可以实现:自定义选中颜色和样式添加选中时的动画效果自定义Item的背景颜色添加高亮时的动画效果添加一些动画暗示用户点击等等...... 7、支持自定义按钮大小,支持自定义点击事件ESTabBarController支持自定义按钮的大小,你可以轻松定制不规则大小的tab按钮。当按钮frame大于TabBar时,通过HitTest方法使其超出TabBar区域点击仍然有效。 另外,ESTabBarController能够自定义点击事件,并通过一个block回调给上层处理。中间带有较大按钮样式:带有特殊提醒框样式:自定义按钮点击事件:8、支持默认通知样式如果直接使用ESTabBarController进行初始化,你会得到与UITabBarController完全相同的仿系统通知样式UITabBarController样式:ESTabBarController仿系统样式:9、支持自定义通知样式使用ESTabBarController可以实现:自定义提醒动画自定义提醒样式等等...... 10、支持Lottie通过自定义ContentView,能够添加Lottie的LAAnimationView到Item支持环境Xcode 8 or lateriOS 8.0 or laterARCSwift 3 or later
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值