gpt4 book ai didi

ios - 从 Storyboard 中实现 PageMenu/初始化 View Controller

转载 作者:搜寻专家 更新时间:2023-11-01 05:47:01 25 4
gpt4 key购买 nike

我正试图让这个 pod 在我的项目中工作,但我一直在理解这个位是如何工作的:

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)

我见过一些东西说我需要用我在 Storyboard 中设置的 Storyboard ID 初始化 View Controller ,但是当我尝试做一些像

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

但老实说,我不知道在哪里/什么时候放那个/如果那是什么

我的想法是为页面菜单制作一个 View Controller 数组,以在顶部显示标签栏,但我不确定如何根据我在 Storyboard 中制作的 View 制作该数组。

最佳答案

如果您使用 storyboardIds 进行 View Controller 实例化,请修改上述答案。

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)

}

关于ios - 从 Storyboard 中实现 PageMenu/初始化 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39339898/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com