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,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",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)")
            }
        }
    }
    
}

How to create tabbar with ESTabBarController in swift 3.0的更多相关文章

  1. ios – 来自UIAlertController的self.navigationController?.popViewControllerAnimated

    我是新手,但我想我已经掌握了它.这让我的进步很难过.我想要做的是当我们无法找到他的查询的相关数据时向用户抛出错误消息,然后继续将他带回到之前的ViewController.但是,我在这方面遇到了麻烦.在我添加操作的行上,我收到以下错误:’UIViewController?’不是Void的子类型我该怎么做呢?

  2. ios – Swift闭包为AnyObject

    如何将()–>()转换为AnyObject?我试图将它转换为:处理程序为AnyObject,但它给我一个错误说:()–>()不符合协议’AnyObject’解决方法HowcanIcast()->()intoAnyObject?

  3. Twilio电话在iOS和Android中无法正常工作

    我正在尝试使用twilioclient在反应本机应用程序.这里是链接Twiliorepo完成所有设置与反应本机twilio.当我打电话一个数字得到问题.我使用了这个链接中的所有步骤.[tid:com.facebook.react.JavaScript]处理程序不是一个函数.(在“处理程序(rtn)”中,’handler’是未定义的)2016-09-2711:00:57.857[致命][tid:co

  4. iOS Parse Stripe Integration

    所有指南和文档都指向了这个方向.我真的不明白GET/POST是什么以及它如何适合iOSObjective-C编程.关于如何设置它的任何指导都将非常感激.我已经坚持了一段时间了.解决方法Parse的条带API并不像它应该的那样完整.它本身不包含许多功能,但可以通过HTTP请求完成.我必须学习一点Javascript和HTTP请求以获得许多功能.当然,你的第一直觉应该告诉你不要在任何设备上存储CC号码!

  5. swift实现单例模式

    单例模式单例模式有三个要点:1.只有一个实例2.构造函数要私有3.构造过程线程安全实现swift的static构造过程中使用了dispatch_once方法,使得只会构造一次。

  6. swift - The Adapter Pattern

    ThispatternallowstwoobjectsthatproviderelatedfunctionalitytoworktogetherevenwhentheyhaveincompatibleAPIs.Diagram:client:letsearch=SearchTool(dataSources:SalesDataSource(),DevelopmentDataSource());prin

  7. [Swift]UIKit学习之警告框:UIAlertController和UIAlertView

    Important:UIAlertViewisdeprecatediniOS8.(NotethatUIAlertViewDelegateisalsodeprecated.)TocreateandmanagealertsiniOS8andlater,insteaduseUIAlertControllerwithapreferredStyleofUIAlertControllerStyleAlert.

  8. Swift基础之对话框UIAlertController

    varalertController=UIAlertController(title:"标题",message:"这是一个UIAlertController的默认样式",preferredStyle:UIAlertControllerStyle.Alert)varcancelAction=UIAlertAction(title:"取消",style:UIAlertActionStyle.Cance

  9. Swift下弹出对话框

  10. UIAlertController 测试的修正

    作者:dom,原文链接,原文日期:2015-11-25译者:小袋子;校对:lfb_CD;定稿:千叶知风两个月前,我曾发布了一篇如何测试UIAlertController的文章。一个读者发现测试没有如期地起作用:@dasdom你的测试是正常的,但是在MockUIAction中的简便init方法没有被调用。那是因为handler确实被调用了,看起来就像UIAlertAction真的把handler作为内部变量去存储动作的handler闭包。这是非常脆弱的,并且Larhythimx在另一个tweet指出在他的测

随机推荐

  1. Swift UITextField,UITextView,UISegmentedControl,UISwitch

    下面我们通过一个demo来简单的实现下这些控件的功能.首先,我们拖将这几个控件拖到storyboard,并关联上相应的属性和动作.如图:关联上属性和动作后,看看实现的代码:

  2. swift UISlider,UIStepper

    我们用两个label来显示slider和stepper的值.再用张图片来显示改变stepper值的效果.首先,这三个控件需要全局变量声明如下然后,我们对所有的控件做个简单的布局:最后,当slider的值改变时,我们用一个label来显示值的变化,同样,用另一个label来显示stepper值的变化,并改变图片的大小:实现效果如下:

  3. preferredFontForTextStyle字体设置之更改

    即:

  4. Swift没有异常处理,遇到功能性错误怎么办?

    本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容,请发送邮件至dio@foxmail.com举报,一经查实,本站将立刻删除。

  5. 字典实战和UIKit初探

    ios中数组和字典的应用Applicationschedule类别子项类别名称优先级数据包contactsentertainment接触UIKit学习用Swift调用CocoaTouchimportUIKitletcolors=[]varbackView=UIView(frame:CGRectMake(0.0,0.0,320.0,CGFloat(colors.count*50)))backView

  6. swift语言IOS8开发战记21 Core Data2

    上一话中我们简单地介绍了一些coredata的基本知识,这一话我们通过编程来实现coredata的使用。还记得我们在coredata中定义的那个Model么,上面这段代码会加载这个Model。定义完方法之后,我们对coredata的准备都已经完成了。最后强调一点,coredata并不是数据库,它只是一个框架,协助我们进行数据库操作,它并不关心我们把数据存到哪里。

  7. swift语言IOS8开发战记22 Core Data3

    上一话我们定义了与coredata有关的变量和方法,做足了准备工作,这一话我们来试试能不能成功。首先打开上一话中生成的Info类,在其中引用头文件的地方添加一个@objc,不然后面会报错,我也不知道为什么。

  8. swift实战小程序1天气预报

    在有一定swift基础的情况下,让我们来做一些小程序练练手,今天来试试做一个简单地天气预报。然后在btnpressed方法中依旧增加loadWeather方法.在loadWeather方法中加上信息的显示语句:运行一下看看效果,如图:虽然显示出来了,但是我们的text是可编辑状态的,在storyboard中勾选Editable,再次运行:大功告成,而且现在每次单击按钮,就会重新请求天气情况,大家也来试试吧。

  9. 【iOS学习01】swift ? and !  的学习

    如果不初始化就会报错。

  10. swift语言IOS8开发战记23 Core Data4

    接着我们需要把我们的Rest类变成一个被coredata管理的类,点开Rest类,作如下修改:关键字@NSManaged的作用是与实体中对应的属性通信,BinaryData对应的类型是NSData,CoreData没有布尔属性,只能用0和1来区分。进行如下操作,输入类名:建立好之后因为我们之前写的代码有些地方并不适用于coredata,所以编译器会报错,现在来一一解决。

返回
顶部