【发布时间】:2017-08-04 01:05:47
【问题描述】:
如何制作这样一个类似 Instagram 的标签?
我需要制作多个UIViewControllers 还是在一个UIViewController 上制作一些东西?
提前感谢您的帮助!
【问题讨论】:
如何制作这样一个类似 Instagram 的标签?
我需要制作多个UIViewControllers 还是在一个UIViewController 上制作一些东西?
提前感谢您的帮助!
【问题讨论】:
我建议使用 ESTabBarControllerExample https://github.com/eggswift/ESTabBarController 来制作那种自定义的 TabbarController。首先从 github 下载 ESTabbarControllerExample。我们需要使用一些类字母。让我一步一步解释如何使用:
首先安装 CocoaPods
1 打开终端和cd ~ to your project directory
2 运行命令-pod init
3 您的 podfile 应与 - pod
"ESTabBarController-swift" 一起使用并保存
4 并使用命令pod install安装它
打开 .xcworkspace 扩展名的项目文件
1 在项目中我们需要添加Content all swift class 和pop.framework
2 不要使用 add File to 添加 pop.framework。您必须从框架添加并添加其他。
3 在Content文件夹的所有文件import ESTabBarController_swift
StoryBord 资料
1 添加导航控制器并在EST demo的示例代码中添加ExampleNavigationController。 (您也可以添加自己的),但请确保设置其导航自定义 swift 类。
AppDelegate.swift 中的代码内容
您需要在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
为标签栏项目和其他您想在资产中使用的项目添加图像。 希望对你有所帮助。
【讨论】: