SideTown - 为iOS设备创建侧边菜单的最简单方法

边城

SideTown 是为 iOS 设备创建侧边菜单的最简单方法。

边镇

边镇

目录

  1. 安装
  2. 用法
  3. 配置

安装

File > Add Packages..>粘贴到搜索区域此>单击按钮https://github.com/sametkoyuncu/SideTown.gitAdd Package

用法

  • 创建一个名为 BaseViewController 的新 UIViewController 类

class BaseViewController: UIViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
    }
}  
  • 创建您想要的菜单设计

let menuView = UIView(frame: CGRect(x: 0,
                                    y: 0,
                                    width: 280,
                                    height: UIScreen.main.bounds.height))
menuView.backgroundColor = .red
  • Implement SideTown to BaseViewController

import UIKit
import SideTown

class BaseViewController: UIViewController {
    private var sideMenu: SideMenu!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // MARK: - Your Menu View
        // custom menu view inside side menu
        let menuView = UIView(frame: CGRect(x: 0,
                                              y: 0,
                                              width: 280,
                                              height: UIScreen.main.bounds.height))
        menuView.backgroundColor = .red
                        
        // side menu
        let config: MenuConfig = .init(vc: self, customView: menuView)
        sideMenu = SideMenu(config)
    }
    
    func openMenu() {
        sideMenu.openMenu()
    }
    
    func closeMenu() {
        sideMenu.closeMenu()
    }
    
    func toggleMenu() {
        sideMenu.toggleMenu()
    }
 }
  • Create another ViewController subclass of BaseViewController. And add a new button for open menu.

import UIKit
class ViewController: BaseViewController {
    override func viewDidLoad() {
        super.viewDidLoad()
    }
    
    @IBAction func menuButtonTapped(_ sender: Any) {
        super.openMenu()
    }
}
  • Run project
  • For more information checkout sample project 👉 Go

Configuration

Property Type Description isRequired
vc UIViewController It’s necessary for swipe gesture and navigation bar actions.
customView UIView Your design, showing inside the side menu.
position MenuPosition Side menu position. or . The default value is ..left.right.left
backgroundColor UIColor Side menu background color. The default value is ..darkGray.withAlphaComponent(0.7)

GitHub

点击跳转