从故事板实现PageMenu /初始化视图控制器

我试图让这个吊舱在我的项目中工作,我坚持了解如何工作:

https://github.com/uacaps/PageMenu

// Create variables for all view controllers you want to put in the // page menu, initialize them, and add each to the controller array. // (Can be any UIViewController subclass) // Make sure the title property of all view controllers is set // Example: var controller : UIViewController = UIViewController(nibName: "controllerNibName", bundle: nil) controller.title = "SAMPLE TITLE" controllerArray.append(controller) 

我已经看到了一些事情,我需要初始化视图控制器与故事板中设置的故事板ID,但是当我尝试做一些像

 let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil) let vc = storyboard.instantiateViewControllerWithIdentifier("someViewController") as! UIViewController self.presentViewController(vc, animated: true, completion: nil) 

但说实话,我不知道在哪里/什么时候把/如果这甚至是什么

这个想法是为页面菜单制作一个视图控制器来显示顶部的标签栏,但是我不知道如何从视图中创build视图。

干得好。 PageMenu是超级酷,超级定制。 玩的开心。 希望这可以帮助。 如果遇到其他问题,请告诉我。

 var pageMenu: CAPSPageMenu? override func viewDidLoad() { super.viewDidLoad() setupPages() } func setupPages() { var controllerArray: [UIViewController] = [] let firstVC = FirstViewController() firstVC.title = "FirstOne" let secondVC = SecondViewController() secondVC.title = "Another One" let thirdVC = ThirdViewController() thirdVC.title = "And Another One" controllerArray.append(firstVC) controllerArray.append(secondVC) controllerArray.append(thirdVC) // a bunch of random customization let parameters: [CAPSPageMenuOption] = [ .ScrollMenuBackgroundColor(UIColor.quotesBackgroundColor()), .ViewBackgroundColor(UIColor.quotesBackgroundColor()), .SelectionIndicatorColor(UIColor.peterRiverColor()), .BottomMenuHairlineColor(UIColor(red: 70.0/255.0, green: 70.0/255.0, blue: 80.0/255.0, alpha: 1.0)), .MenuHeight(40.0), .MenuItemWidth(100.0), .CenterMenuItems(true), .SelectedMenuItemLabelColor(UIColor.blueColor()) ] pageMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRectMake(0.0, 0.0, self.view.frame.width, self.view.frame.height), pageMenuOptions: parameters) self.view.addSubview(pageMenu!.view) } 

如果使用storyboardIds作为viewcontroller实例化,则修改上述答案。

 var pageMenu: CAPSPageMenu? override func viewDidLoad() { super.viewDidLoad() setupPages() } func setupPages() { let storyboard = UIStoryboard(name: "MyStoryboardName", bundle: nil) var controllerArray: [UIViewController] = [] let firstVC = storyboard.instantiateViewControllerWithIdentifier("FirstViewControlleridentifier") as! FirstViewController firstVC.title = "FirstOne" let secondVC = storyboard.instantiateViewControllerWithIdentifier("SecondViewControlleridentifier") as! SecondViewController secondVC.title = "Another One" let thirdVC = storyboard.instantiateViewControllerWithIdentifier("ThirdViewControlleridentifier") as! ThirdViewController thirdVC.title = "And Another One" controllerArray.append(firstVC) controllerArray.append(secondVC) controllerArray.append(thirdVC) // a bunch of random customization let parameters: [CAPSPageMenuOption] = [ .ScrollMenuBackgroundColor(UIColor.quotesBackgroundColor()), .ViewBackgroundColor(UIColor.quotesBackgroundColor()), .SelectionIndicatorColor(UIColor.peterRiverColor()), .BottomMenuHairlineColor(UIColor(red: 70.0/255.0, green: 70.0/255.0, blue: 80.0/255.0, alpha: 1.0)), .MenuHeight(40.0), .MenuItemWidth(100.0), .CenterMenuItems(true), .SelectedMenuItemLabelColor(UIColor.blueColor()) ] pageMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRectMake(0.0, 0.0, self.view.frame.width, self.view.frame.height), pageMenuOptions: parameters) self.view.addSubview(pageMenu!.view) } 

大卫更新了Swift-3版本

Podfile为Swift-3
pod'PageMenu',:git =>' https://github.com/orazz/PageMenu '

 func setupPages() { var controllerArray: [UIViewController] = [] let firstVC = FirstVC() firstVC.title = "First" let secondVC = SecondVC() secondVC.title = "Second" let thirdVC = ThirdVC() thirdVC.title = "Third" controllerArray.append(firstVC) controllerArray.append(secondVC) controllerArray.append(thirdVC) let parameters: [CAPSPageMenuOption] = [ .scrollMenuBackgroundColor(.blue), .viewBackgroundColor(.white), .selectionIndicatorColor(.white), .bottomMenuHairlineColor(.white), .menuHeight(40.0), .menuItemWidth(self.view.frame.width/3), .centerMenuItems(true), .selectedMenuItemLabelColor(.white), .unselectedMenuItemLabelColor(.white), .menuMargin(0.0) ] pageMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRect(x:0,y:64,width:self.view.frame.width ,height:self.view.frame.height) , pageMenuOptions: parameters) self.view.addSubview(pageMenu!.view) } 

或者你可以使用这个回购。对于RnD来说,这是非常简单和容易理解的。 (Swift 3代码)

https://github.com/lakshikabhardwaj/LBViewControllerCollection

  let mainViewController = CPPageMenuVC(nibName: "CPPageMenuVC", bundle: nil) let pageMenuarray :[PageModal] = [PageModal(pageTitle: "Cat", pageVC: cpCatVC),PageModal(pageTitle: "Cow", pageVC: cowCX),PageModal(pageTitle: "Chat", pageVC: cpCatVC),PageModal(pageTitle: "ElephantElephant", pageVC: elephantVC)] pageMenuVC.pageArray = pageMenuarray