Him*_*iya 4 tabbar uitabbarcontroller ios swift3
我想从故事板创建一个标签栏,我创建它,但当单击标签栏时,图像没有显示和一些图像我想要标签栏像
而我得到这个
当我点击其显示的任何标签栏项目时
这是我在配置文件视图控制器中使用的代码
class ProfileViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
UIApplication.shared.statusBarStyle = .default
self.tabBarController?.tabBar.isHidden = false
UITabBar.appearance().tintColor = UIColor.init(patternImage: UIImage.init(named: "ic_home_tab_profile_sel.png")!)
// Do any additional setup after loading the view.
}
}
Run Code Online (Sandbox Code Playgroud)
任何帮助都可以欣赏.先感谢您.
我建议使用ESTabBarControllerExample https://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添加导航控制器也可以ExampleNavigationController从EST演示的示例代码中添加.(您也可以添加自己的)但请确保将其导航类设置为自定义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
Run Code Online (Sandbox Code Playgroud)
为标签栏项添加图像以及要在资产中使用的其他图像.希望对你有所帮助.
示例项目:https://github.com/nitingohel/CustomTabCenterBig
| 归档时间: |
|
| 查看次数: |
17682 次 |
| 最近记录: |