Reputation: 2373
I download and run ESTabBarController fine but I don't know why when I create my own project and use code from Example, my large button still small??
While image below is from example project as my expectation as well
Here is my code
AppDelegate.swift
let TabbarNavigationController = ViewController.customIrregularityStyle(delegate: nil)
self.window?.rootViewController = TabbarNavigationController
ViewController.swift
static func customIrregularityStyle(delegate: UITabBarControllerDelegate?) -> NavigationController {
let tabBarController = ESTabBarController()
tabBarController.delegate = delegate
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(IrregularityBasicContentView(), title: "Home", image: UIImage(named: "home"), selectedImage: UIImage(named: "home_1"))
v2.tabBarItem = ESTabBarItem.init(IrregularityBasicContentView(), title: "Find", image: UIImage(named: "find"), selectedImage: UIImage(named: "find_1"))
v3.tabBarItem = ESTabBarItem.init(IrregularityBasicContentView(), title: nil, image: UIImage(named: "photo_verybig"), selectedImage: UIImage(named: "photo_verybig"))
v4.tabBarItem = ESTabBarItem.init(IrregularityBasicContentView(), title: "Favor", image: UIImage(named: "favor"), selectedImage: UIImage(named: "favor_1"))
v5.tabBarItem = ESTabBarItem.init(IrregularityBasicContentView(), title: "Me", image: UIImage(named: "me"), selectedImage: UIImage(named: "me_1"))
tabBarController.viewControllers = [v1, v2, v3, v4, v5]
let navigationController = NavigationController.init(rootViewController: tabBarController)
tabBarController.title = "Example"
return navigationController
}
Any idea?
Upvotes: 0
Views: 1832
Reputation: 1775
Try to use custom tabBar and add your button in centre of tabBar Like This
If you want to use ESTabBarController follow the below steps.
Step 1:
Download the sample project of ESTabBarController and install pod "ESTabBarController-swift"
in your project
Step 2: Copy all the assets from sample project into your existing project
Step 3:
Copy ExampleBasicContentView
, ExampleBouncesContentView
, ExampleIrregularityContentView
, ExampleNavigationController
Classes from sample project
NOTE - If you got error “No such module 'pop'” in “
ExampleIrregularityBasicContentView
” Then remove that line and removefunc playMaskAnimation
Or install pod pop
Step 4:
In StoryBoard Embbed your viewController
in navigationController and assign ExampleNavigationController
class to your navigationController
Step 5:
import ESTabBarController_swift
and add UITabBarControllerDelegate
in your AppDelegate
class
Add paste following code in your AppDelegate
class
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
let tabBarController = ESTabBarController()
tabBarController.delegate = self
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 = ViewController()
let v2 = ViewController()
let v3 = ViewController()
let v4 = ViewController()
let v5 = ViewController()
v1.tabBarItem = ESTabBarItem.init(ExampleIrregularityBasicContentView(), title: "Home", image: UIImage(named: "home"), selectedImage: UIImage(named: "home_1"))
v2.tabBarItem = ESTabBarItem.init(ExampleIrregularityBasicContentView(), title: "Find", image: UIImage(named: "find"), selectedImage: UIImage(named: "find_1"))
v3.tabBarItem = ESTabBarItem.init(ExampleIrregularityContentView(), title: nil, image: UIImage(named: "photo_verybig"), selectedImage: UIImage(named: "photo_verybig"))
v4.tabBarItem = ESTabBarItem.init(ExampleIrregularityBasicContentView(), title: "Favor", image: UIImage(named: "favor"), selectedImage: UIImage(named: "favor_1"))
v5.tabBarItem = ESTabBarItem.init(ExampleIrregularityBasicContentView(), title: "Me", image: UIImage(named: "me"), selectedImage: UIImage(named: "me_1"))
tabBarController.viewControllers = [v1, v2, v3, v4, v5]
let navigationController = ExampleNavigationController.init(rootViewController: tabBarController)
self.window?.rootViewController = navigationController
return true
}
You can find demo here
ScreenShot :
Upvotes: 2