我建议使用ESTabBarControllerExamplehttps://github.com/eggswift/ESTabBarController使这一样定制的TabbarController.First从GitHub下载ESTabbarControllerExample。我们需要使用一些类信函。让我来介绍一下如何使用分步:
首先安装的CocoaPods
1个打开终端和cd ~ to your project directory
2执行命令 - pod init
3你podfile应与 - pod "ESTabBarController-swift"
一起使用并保存
4用命令安装pod install
.xcworkspace扩展的开放项目文件
1在项目中,我们需要添加Content
所有SWIFT类和pop.framework
2不要添加pop.framework使用添加文件到。您必须从Framework添加并添加其他。
3在内容文件夹中的所有文件import ESTabBarController_swift
StoryBord东西
1添加导航控制器ANE也从EST演示示例代码添加ExampleNavigationController
。 (你也可以自己添加),但是确保你设置了它的导航类自定义swift类。
代码在AppDelegate的东西。迅速
你需要做下面的代码在侧didFinishLaunchingWithOptions
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(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)
tabBarController.title = "Example"
self.window?.rootViewController = navigationController
return true
添加映像进行的TabBar物品等要在资产使用的。 希望对你有所帮助。
示例项目:https://github.com/nitingohel/CustomTabCenterBig