viccarre / PagingMenuController

Paging view controller with customizable menu in Swift

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

CI Status Carthage compatible Version License Platform

This library is inspired by PageMenu

Updates

See CHANGELOG for details

Description

Standard menu mode

Flexible width

Fixed width

Segmented control mode

Infinite mode

To be updated soon...

Customization

  • default page index to show as a first view
defaultPage: Int
  • scrollEnabled for paging view. Set false in case of using swipe-to-delete on your table view
scrollEnabled: Bool
  • background color for menu view
backgroundColor: UIColor
  • background color for selected menu item
selectedBackgroundColor: UIColor
  • text color for menu item
textColor: UIColor
  • text color for selected menu item
selectedTextColor: UIColor
  • font for menu item text
font: UIFont
  • font for selected menu item text
selectedFont: UIFont
  • menu position
menuPosition: MenuPosition

public enum MenuPosition {
    case Top
    case Bottom
}
  • height for menu view
menuHeight: CGFloat
  • margin for each menu item
menuItemMargin: CGFloat
  • duration for menu item view animation
animationDuration: NSTimeInterval
  • menu display mode and scrolling mode
menuDisplayMode: MenuDisplayMode

public enum MenuDisplayMode {
    case Standard(widthMode: MenuItemWidthMode, centerItem: Bool, scrollingMode: MenuScrollingMode)
    case SegmentedControl
    case Infinite(widthMode: MenuItemWidthMode) // Requires three paging views al least
}

public enum MenuItemWidthMode {
    case Flexible
    case Fixed(width: CGFloat)
}

public enum MenuScrollingMode {
  case ScrollEnabled
  case ScrollEnabledAndBouces
  case PagingEnabled
}

if centerItem is true, selected menu item is always on center

if MenuScrollingMode is ScrollEnabled or ScrollEnabledAndBouces, menu view allows scrolling to select any menu item if MenuScrollingMode is PagingEnabled, menu item should be selected one by one

  • menu item mode
public var menuItemMode = MenuItemMode.Underline(height: 3, color: UIColor.whiteColor(), horizontalPadding: 0, verticalPadding: 0)
public enum MenuItemMode {
    case None
    case Underline(height: CGFloat, color: UIColor, horizontalPadding: CGFloat, verticalPadding: CGFloat)
    case RoundRect(radius: CGFloat, horizontalPadding: CGFloat, verticalPadding: CGFloat, selectedColor: UIColor)
}

Usage

import PagingMenuController to use PagingMenuController in your file.

Using Storyboard

let viewController = self.storyboard?.instantiateViewControllerWithIdentifier("ViewController") as! ViewController
viewController.title = "Menu title"
let viewControllers = [viewController]

let pagingMenuController = self.childViewControllers.first as! PagingMenuController

let options = PagingMenuOptions()
options.menuHeight = 60
options.menuDisplayMode = .Standard(widthMode: .Flexible, centerItem: true, scrollingMode: .PagingEnabled)
pagingMenuController.setup(viewControllers: viewControllers, options: options)
  • You should add ContainerView into your view controller's view and set PagingMenuController as the embedded view controller's class

Coding only

let viewController = UIViewController()
viewController.title = "Menu title"
let viewControllers = [viewController]

let options = PagingMenuOptions()
options.menuItemMargin = 5
options.menuDisplayMode = .SegmentedControl
let pagingMenuController = PagingMenuController(viewControllers: viewControllers, options: options)

self.addChildViewController(pagingMenuController)
self.view.addSubview(pagingMenuController.view)
pagingMenuController.didMoveToParentViewController(self)

Delegate methods (optional)

pagingMenuController.delegate = self
func willMoveToMenuPage(page: Int) {
}

func didMoveToMenuPage(page: Int) {
}

Requirements

iOS8+
Swift 1.2+
Xcode 6.3+

For iOS7 support
Follow Manual Installation

Swift 1.2
Please use swift_1.2 branch, but it doesn't have full features.

Podfile
pod 'PagingMenuController', :git => 'https://github.com/kitasuke/PagingMenuController', :branch => 'swift_1.2'

Carfile
github "kitasuke/PagingMenuController" "swift_1.2"

Installation

CocoaPods

PagingMenuController is available through CocoaPods. To install it, simply add the following line to your Podfile:

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
use_frameworks!

pod "PagingMenuController"

Then, run pod install

In case you haven't installed CocoaPods yet, run the following command

$ gem install cocoapods

Carthage

PagingMenuController is available through Carthage.

To install PagingMenuController into your Xcode project using Carthage, specify it in your Cartfile:

github "kitasuke/PagingMenuController"

Then, run carthage update

You can see Carthage/Build/iOS/PagingMenuController.framework now, so drag and drop it to Linked Frameworks and Libraries in General menu tab with your project. Add the following script to New Run Script Phase in Build Phases menu tab.

/usr/local/bin/carthage copy-frameworks

Also add the following script in Input Files

$(SRCROOT)/Carthage/Build/iOS/PagingMenuController.framework

In case you haven't installed Carthage yet, run the following command

$ brew update
$ brew install carthage

Manual

Copy all the files in Pod/Classes directory into your project.

License

PagingMenuController is available under the MIT license. See the LICENSE file for more info.

About

Paging view controller with customizable menu in Swift

License:MIT License


Languages

Language:Swift 96.8%Language:Ruby 2.3%Language:Objective-C 0.9%