我目前正在实现 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)
}
但问题是当我在我的侧边菜单中显示这个 ContainerVC 时,它也是第三方库 FAPanels。我在 xlpager 选项卡中遇到间距问题。 间距标签栏图像
左侧菜单代码
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)
})
}
}