Latest 1.0.2
Homepage https://github.com/antelosdev/RGNPageMenu
License MIT
Platforms ios 8.0, requires ARC
Authors

RGNPageMenu.swift

Version
License
Platform
Carthage compatible

RGNPageMenu is easily customizable paging menu controller.

rgn-page-menu-sample-1

Example Usage

This is from Demo project.

  • Set the initial page index
  • Add non-page item (such as "Add Page Button") to menu.
import UIKit

class ViewController: UIViewController {

    var titles = ["Python", "C++", "Ruby", "Swift", "Go", "Elixir"]
    var viewControllers:[String:UIViewController] = [:]
    var pageMenu: RGNPageMenu!

    override func viewDidLoad() {
        super.viewDidLoad()

        let options:[RGNPageMenuOption] = [
            .initialPageIndex(1),
            .menuHeight(80.0),
            .menuItemMargin(20.0),
            .menuItemPadding(20.0)
        ]
        self.pageMenu = RGNPageMenu(frame: self.view.frame, delegate: self, options: options)
        self.view.addSubview(self.pageMenu.view)

        self.pageMenu.menuScrollView.backgroundColor = UIColor(red: 250.0/255, green: 250.0/255, blue: 250.0/255, alpha: 1.0)
    }
}

// MARK: - RGNPageMenuDelegate
extension ViewController: RGNPageMenuDelegate {

    // Number of controllers
    func rgnNumberOfControllers() -> Int {
        return titles.count
    }

    // Controller at index
    func rgnController(atIndex index: Int) -> UIViewController {
        let t = titles[index]
        if let vc = self.viewControllers[t] {
            return vc
        } else {
            let vc = MyTableViewController()
            vc.title = t
            self.viewControllers[t] = vc
            return vc
        }
    }

    // Number of menu items
    func rgnNumberOfMenuItems() -> Int {
        return titles.count + 1
    }

    // Menu label at index
    func rgnMenuLabel(atIndex index: Int) -> UILabel {
        let label = UILabel()
        if index == titles.count {
            label.text = "Add Language"
        } else {
            label.text = titles[index]
        }
        label.font = UIFont.systemFont(ofSize: 13.0)
        if index == self.pageMenu.currentPageIndex {
            label.textColor = UIColor.white
            label.backgroundColor = UIColor(red: 236.0/255, green: 109.0/255, blue: 109.0/255, alpha: 1.0)
            label.layer.cornerRadius = 10.0
            label.layer.masksToBounds = true
        } else {
            label.textColor = UIColor(red: 116.0/255, green: 116.0/255, blue: 116.0/255, alpha: 1.0)
        }
        label.textAlignment = NSTextAlignment.center
        label.sizeToFit()
        if label.frame.size.width < 44 {
            label.frame.size.width = 44
        }
        label.frame.size.height += 8.0
        return label
    }

    // Tap handler for menu items (optional)
    func rgnMenuItemTapped(atIndex index: Int) {
        if index == titles.count {
            self.titles.append("New Language(index)")
            self.pageMenu.reloadData(resetPosition: true)
        } else {
            self.pageMenu.moveToPage(index)
        }
    }

    // Page changed (optional)
    func rgnDidMoveTo(pageIndex index: Int) {
        let vc = self.rgnController(atIndex: index) as! MyTableViewController
        vc.viewDidPresent()
    }

}

Runtime Requirements

  • iOS 8.0 or later
  • Xcode 8.0 – Swift3.0

Installation

CocoaPods

RGNPageMenu is available through CocoaPods.

To install add the following line to your Podfile:

pod 'RGNPageMenu'

Carthage

RGNPageMenu is also available through Carthage.

Add following line to Cartfile and follow this instruction.

github "antelosdev/RGNPageMenu"

Manual Installation

The class file required for RGNPageMenu is located in the RGNPageMenu folder in the root of this repository as listed below:

  • RGNPageMenu.swift

Contribution

Please file issues or submit pull requests for anything you’d like to see! We’re waiting! :)

License

RGNPageMenu is released under the MIT license.

Latest podspec

{
    "name": "RGNPageMenu",
    "version": "1.0.2",
    "summary": "Add easily customizable page menu.",
    "description": "- Add easily customizable page menu.",
    "homepage": "https://github.com/antelosdev/RGNPageMenu",
    "license": "MIT",
    "authors": {
        "Iwark": "[email protected]"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source": {
        "git": "https://github.com/antelosdev/RGNPageMenu.git",
        "tag": "1.0.2"
    },
    "source_files": "RGNPageMenu/**/*.swift",
    "requires_arc": true
}

Pin It on Pinterest

Share This