一、方法方式处理
@IBAction func btn1(_ sender: UIButton) { let vc = customedPageController() vc.hidesBottomBarWhenPushed = true; self.navigationItem.backBarButtonItem = UIBarButtonItem.init() self.navigationController?.pushViewController(vc,animated: true } // MARK: - An example of `PageController` fileprivate func customedPageController() -> WMPageController { let vcClasses:[AnyClass] = [AllOrderVC().classForCoder,WaitPaymentOrderVC().classForCoder,WaitDeliveryOrderVC().classForCoder,WaitReceiveOrderVC().classForCoder,WaitEvaluateVC().classForCoder] let titles = ["全部订单","待付款","待发货","待收货","待评价"] let pageVC = WMPageController(viewControllerClasses: vcClasses,andTheirTitles: titles) // pageVC.tabBarController?.tabBar.isHidden = true pageVC.title="我的订单" pageVC.itemsWidths = [70,50,50] //每个 MenuItem 的宽度‘ pageVC.menuView?.frame = CGRect.init(x: 0,y: 0,width: DeviceMaxWidth,height: 44) //导航栏高度 pageVC.menuView?.backgroundColor = UIColor.red //导航栏颜色 pageVC.postNotification = true // pageVC.bounces = true pageVC.titleSizeSelected=13 //选中时的标题尺寸 pageVC.titleSizeNormal=14 //非选中时的标题尺寸 pageVC.menuViewStyle = .line //Menu view 的样式,默认为无下划线 pageVC.titleColorSelected=UIColor.red //标题选中时的颜色,颜色是可动画的. pageVC.titleColorNormal=UIColor.black //标题非选择时的颜色,颜色是可动画的 pageVC.scrollView?.height = 100 return pageVC }
二 自定义 vc
// // CustomOrderVC.swift // ALSPetsMail // // Created by 冰泪 on 2017/12/13. // Copyright © 2017年 冰泪. All rights reserved. // import UIKit import WMPageController class CustomOrderVC: WMPageController { let vcClasses:[AnyClass] = [AllOrderVC().classForCoder,WaitEvaluateVC().classForCoder] let titles1:[String] = ["全部订单","待评价"] private func createUI() { self.viewControllerClasses = vcClasses self.titles = titles1 self.title="我的订单" self.itemsWidths = [80,50] //每个 MenuItem 的宽度‘ // self.menuView?.backgroundColor = UIColor.red //导航栏颜色 self.postNotification = true // self.bounces = true self.titleSizeSelected=13 //选中时的标题尺寸 self.titleSizeNormal=13 //非选中时的标题尺寸 self.menuViewStyle = .line //Menu view 的样式,默认为无下划线 self.titleColorSelected=UIColor.red //标题选中时的颜色,颜色是可动画的. self.titleColorNormal=UIColor.black //标题非选择时的颜色,颜色是可动画的 } override func viewDidLoad() { super.viewDidLoad() createUI() } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } } extension CustomOrderVC { override func numbersOfChildControllers(in pageController: WMPageController) -> Int { return titles1.count } override func pageController(_ pageController: WMPageController,viewControllerAt index: Int) -> UIViewController { let vc : UIViewController! switch index { case 0: vc = AllOrderVC() case 1: vc = WaitPaymentOrderVC() case 2: vc = WaitDeliveryOrderVC() case 3: vc = WaitReceiveOrderVC() default: vc = WaitEvaluateVC() } return vc } override func pageController(_ pageController: WMPageController,titleAt index: Int) -> String { return titles1[index] } override func pageController(_ pageController: WMPageController,preferredFrameFor menuView: WMMenuView) -> CGRect { let navH:CGFloat! = (self.navigationController?.navigationBar.max_y) return CGRect(x: 0,y: navH,height: 45) } override func pageController(_ pageController: WMPageController,preferredFrameForContentView contentView: WMScrollView) -> CGRect { let navH:CGFloat! = (self.navigationController?.navigationBar.max_y) return CGRect.init(x: 0,y: navH+45,height: DeviceMaxHeight-navH-45) } }
/// 获取或设置 y public var max_y: CGFloat { get { return frame.origin.y + frame.size.height } set { frame.origin.y = max_y - frame.size.height } }
原文链接:https://www.f2er.com/swift/320843.html