我目前正在实现XLPagerTabStrip(https://github.com/xmartlabs/XLPagerTabStrip),它可以有效地在视图控制器顶部创建一个标签栏。我制作了一个containerVC
class ContainerVC: ButtonBarPagerTabStripViewController {
let purpleInspireColor = #colorLiteral(red: 0.09759091236, green: 0.5779017098, blue: 1, alpha: 1)
override func viewDidLoad() {
super.viewDidLoad()
//self.navigationController?.title = "Oreder Detail"
self.title = "Order Detail"
settings.style.buttonBarBackgroundColor = #colorLiteral(red: 0.09759091236, green: 0.5779017098, blue: 1, alpha: 1)
settings.style.buttonBarItemBackgroundColor = .white
settings.style.selectedBarBackgroundColor = #colorLiteral(red: 0.09759091236, green: 0.5779017098, blue: 1, alpha: 1)
settings.style.buttonBarItemFont = .boldSystemFont(ofSize: 16)
settings.style.selectedBarHeight = 1.5
settings.style.buttonBarMinimumLineSpacing = 0
settings.style.buttonBarItemTitleColor = #colorLiteral(red: 0.09759091236, green: 0.5779017098, blue: 1, alpha: 1)
settings.style.buttonBarItemsShouldFillAvailiableWidth = true
settings.style.buttonBarLeftContentInset = 0
settings.style.buttonBarRightContentInset = 0
changeCurrentIndexProgressive = { [weak self] (oldCell: ButtonBarViewCell?, newCell: ButtonBarViewCell?, progressPercentage: CGFloat, changeCurrentIndex: Bool, animated: Bool) -> Void in
guard changeCurrentIndex == true else { return }
oldCell?.label.textColor = #colorLiteral(red: 0.6666666865, green: 0.6666666865, blue: 0.6666666865, alpha: 1)
newCell?.label.textColor = self?.purpleInspireColor
}
}
override func viewControllers(for pagerTabStripController: PagerTabStripViewController) -> [UIViewController] {
let child_1 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PreOrderVC")
let child_2 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PendingVC")
let child_3 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "PreparingVC")
let child_4 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "HoldVC")
let child_5 = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "CompleteVC")
return [child_1,child_2, child_3, child_4, child_5]
}
@IBAction func leftContainerMenuTapped(_ sender: UIBarButtonItem) {
panel?.configs = FAPanelConfigurations()
panel?.openLeft(animated: true)
}}
我在2个不同的地方使用了containerVC,首先在按钮操作中实例化了viewcontroller,这将显示得很好。如下所示:
@IBAction func orderBtnTapped(_ sender: UIButton) {
// let vc = ContainerVC()
//self.present(vc, animated: true, completion: nil)
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "ContainerVC") as! ContainerVC
navigationController?.pushViewController(vc, animated: true)
}
但是问题是,当我在侧面菜单(也是第三方库FAPanels)中显示此ContainerVC时。我在xlpager标签中遇到间距问题。 Spacing Tab Bar Image
左侧菜单的代码
override func viewWillAppear(_ animated: Bool) {
identifierArr = ["HomeVC" , "ContainerVC" ,"floorTableVC", "KitchenScreenVC","KitchenLinesVC" ,"DriverScreenVC", "ReportsContainerVC"]
}
override func viewWillDisappear(_ animated: Bool) {
identifierArr.removeAll()
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
self.imageProfile.layer.cornerRadius = self.imageProfile.frame.size.width / 2;
self.imageProfile.clipsToBounds = true
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return menuOptions.count
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 50
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = leftMenuTableView.dequeueReusableCell(withIdentifier: "SideMenuCell", for: indexPath) as! LeftMenuVCCell
cell.leftSideMenu.text = menuOptions[indexPath.row]
cell.selectionStyle = .none
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let identifier = identifierArr[indexPath.row]
let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let homeVC: UIViewController = mainStoryboard.instantiateViewController(withIdentifier: identifier)
let centerNavVC = UINavigationController(rootViewController: homeVC)
panel!.configs.bounceOnCenterPanelChange = true
panel!.center(centerNavVC, afterThat: {
print("Executing block after changing center panelVC From Left Menu")
// _ = self.panel!.left(nil)
})
}
}