我使用过PageMenu Library。
我使用过swift而不是故事板。
https://github.com/HighBay/PageMenu
以下是源代码。
ProjectDetailViewController.swift
class ProjectDetailViewController : UIViewController, CAPSPageMenuDelegate{
var projectId:NSInteger!
var firstView: FirstViewController!
var secondView: SecondViewController!
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.whiteColor()
self.title = "PageMenu"
firstView = FirstViewController()
secondView = SecondViewController()
firstView.title = "test1"
secondView.title = "test2"
var controllerArray : [UIViewController] = []
controllerArray.append(firstView)
controllerArray.append(secondView)
let parameters: [CAPSPageMenuOption] = [
.MenuItemSeparatorWidth(0.0),
.UseMenuLikeSegmentedControl(true),
.MenuItemSeparatorPercentageHeight(0.0),
.SelectedMenuItemLabelColor(UIColor.hex("#ffee58", alpha: 1)),
.ScrollMenuBackgroundColor(UIColor.hex("#fffde7", alpha: 1)),
.SelectionIndicatorColor(UIColor.hex("#ffee58", alpha: 1)),
]
let topMargin:CGFloat = UIApplication.sharedApplication().statusBarFrame.size.height+self.navigationController!.navigationBar.frame.size.height;
let pageMenu = CAPSPageMenu(viewControllers: controllerArray, frame: CGRectMake(0.0, topMargin, self.view.frame.width, self.view.frame.height-topMargin), pageMenuOptions: parameters)
pageMenu.delegate = self
self.addChildViewController(pageMenu)
self.view.addSubview(pageMenu.view)
pageMenu.didMoveToParentViewController(self)
}
func willMoveToPage(controller: UIViewController, index: Int){
NSLog("willMoveToPage");
}
func didMoveToPage(controller: UIViewController, index: Int){
NSLog("didMoveToPage");
}
}
FirstViewController.swift
class FirstViewController:UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
NSLog("x = %f y = %f width = %f height = %f", self.view.frame.origin.x, self.view.frame.origin.y, self.view.frame.size.width, self.view.frame.size.height)
self.view.backgroundColor = UIColor.blueColor()
}
}
SecondViewController.swift
class SecondViewController:UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.view.backgroundColor = UIColor.greenColor()
}
}
感谢。