问题描述
我想从故事板创建一个标签栏并创建它但是当时单击标签栏时图像未显示而某些图像我想要标签栏
i want to create one tab bar from storyboard and i create it but when click on tab bar at that time image is not showing and some images i want tab bar like
和我得到了这个
当我点击任何标签栏项目时,它显示为
这是我在配置文件视图控制器中使用的代码
Here is my code that i use in profile view controller
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.
}
}
任何帮助都可以升值。
提前谢谢。
推荐答案
我建议使用 ESTabBarControllerExample 制作这种自定义TabbarController.First下载ESTabbarControllerExample来自github。我们需要使用一些课堂信。让我解释一下如何逐步使用:
I suggest to use ESTabBarControllerExample https://github.com/eggswift/ESTabBarController to making that kind of custom TabbarController.First Download the ESTabbarControllerExample from github. We need to use some class letter on. Let me explain how to use step by step:
-
首先安装CocoaPods
1打开终端, cd~到项目目录
2运行命令 - pod init
2 Run the command - pod init
3您的podfile应与 - pod $ b一起使用$ bESTabBarController-swift
并保存
3 Your podfile should be use with - pod"ESTabBarController-swift"
and save it
4并使用命令 pod install
打开.xcworkspace扩展程序的项目文件
1在项目中,我们需要添加所有swift类和
1 In project we need to add
Content
all swift class and pop.framework
2不要使用添加Fil添加pop.framework到。你必须从Framework添加并添加Others。
2 Don't add pop.framework using add File to. you must be add from Framework and add Others.
3在Content文件夹的所有文件
import ESTabBarController_swift
3 In Content folder's all file
import ESTabBarController_swift
StoryBord资料
1添加导航控制器还添加
示例代码EST demo中的ExampleNavigationController
。 (您也可以添加自己的)但请确保将其导航类设置为自定义swift类。
1 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.
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
为Tabbar项添加图像您想要在资产中使用的其他内容。
希望对您有所帮助。
Add Images for Tabbar items and other that you want to use for in Assets.Hope that helps for you.
示例项目:
这篇关于如何在swift 3.0中使用自定义UI创建tabbar的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!