YNDropDownMenu 3.1.0

YNDropDownMenu 3.1.0

测试已测试
语言语言 SwiftSwift
许可 MIT
发布最后发布2019年3月
SPM支持 SPM

[younatics] 维护。




YNDropDownMenu

Awesome Version Carthage Compatible Docs License: MIT Build Status Platform Swift 5.0

更新

详见 变更日志

简介

适用于 iOS 的合格下拉菜单,用 Swift 5 编写,当用户点击下拉菜单时,会显示相关项目的视图。您可以自定义下拉视图(例如,UITableView、UICollectionView 等)。

demo demo2

要求

YNDropDownMenu 用 Swift 5 编写,兼容 iOS 8.0+。

安装

Cocoapods

YNDropDownMenu可以通过CocoaPods获取。要安装它,只需将以下行添加到您的Podfile中

pod 'YNDropDownMenu'

Carthage

github "younatics/YNDropDownMenu"

使用方法

import YNDropDownMenu

使用frame[CGRect],Views[UIView]和Titles[String]初始化视图

let view = YNDropDownMenu(frame:frame, dropDownViews: dropDownViews, dropDownViewTitles: ["Apple", "Banana", "Kiwi", "Pear"])
self.addSubview(view)

完成!

继承YNDropDownView(如果需要)

class DropDownView: YNDropDownView {
   // override method to call open & close
    override func dropDownViewOpened() {
        print("dropDownViewOpened")
    }
    
    override func dropDownViewClosed() {
        print("dropDownViewClosed")
    }

    // Hide Menu
    self.hideMenu()

    // Change Menu Title At Index
    self.changeMenu(title: "Changed", at: 1)
    self.changeMenu(title: "Changed", status: .selected, at: 1)

    // Change View At Index 
    self.changeView(view: UIView(), at: 3)

    // Always Selected Menu
    self.alwaysSelected(at: 0)
    self.normalSelected(at: 0)
}

自定义

显示和隐藏菜单

view.showAndHideMenu(at:1)

// When view is already opened
view.hideMenu()

禁用和启用菜单

view.disabledMenu(at: 2)
view.enabledMenu(at: 3)

始终/正常选中按钮标签

view.alwaysSelected(at: 0)
view.normalSelected(at: 0)

按钮图像的3种情况(正常、选中、禁用)

view.setStatesImages(normalImages: [UIImage(named: "arrow_nor")], selectedImages: [UIImage(named: "arrow_sel")], disabledImages: [UIImage(named: "arrow_dim")])

标签颜色的3种情况

view.setLabelColorWhen(normal: UIColor.black, selected: UIColor.blue, disabled: UIColor.gray)

标签字体的3种情况

view.setLabelFontWhen(normal: UIFont.systemFont(ofSize: 12), selected: UIFont.boldSystemFont(ofSize: 12), disabled: UIFont.systemFont(ofSize: 12))

BlurEffectView

// Enadbled or Disabled first (Default true)
view.backgroundBlurEnabled = false

// Use this line if you want to change UIBlurEffectStyle
view.blurEffectStyle = .light

// Or customize blurEffectView(UIView)
let backgroundView = UIView()
backgroundView.backgroundColor = UIColor.black
view.blurEffectView = backgroundView

// Animation end alpha
view.blurEffectViewAlpha = 0.7

动画持续时间

view.showMenuDuration = 0.5
view.hideMenuDuration = 0.3

动画速度,阻尼

view.showMenuSpringVelocity = 0.5
view.showMenuSpringWithDamping = 0.8

view.hideMenuSpringVelocity = 0.9
view.hideMenuSpringWithDamping = 0.8

根据索引更改菜单标题

view.changeMenu(title: "Changed", at: 1)
view.changeMenu(title: "Changed", status: .selected, at: 1)

根据索引更改视图

view.changeView(view: UIView(), at: 3)

更改下划线

view.bottomLine.backgroundColor = UIColor.black
view.bottomLine.isHidden = false

废弃

extension YNDropDownMenu {
    @available(*, deprecated, message: "use init(frame: CGRect, dropDownViews: [UIView], dropDownViewTitles: [String]) instead")
    public init(frame: CGRect, YNDropDownViews: [YNDropDownView], dropDownViewTitles: [String])

    @available(*, deprecated, message: "use alwaysSelected(at index: Int) instead")
    open func alwaysSelectedAt(index: Int) {
        self.alwaysSelected(at: index)
    }
    
    @available(*, deprecated, message: "use disabledMenu(at index: Int) instead")
    open func disabledMenuAt(index: Int) {
        self.disabledMenu(at: index)
    }
    
    @available(*, deprecated, message: "use enabledMenu(at index: Int) instead")
    open func enabledMenuAt(index: Int) {
        self.enabledMenu(at: index)
    }

    @available(*, deprecated, message: "use showAndHideMenu(at index: Int) instead")
    open func showAndHideMenuAt(index: Int) {
        self.showAndHideMenu(at: index)
    }
}

extension YNDropDownView {
    @available(*, deprecated, message: "use changeMenu(title: String, at index: Int) instead")
    open func changeMenuTitleAt(index: Int, title: String) {
        self.delegate?.changeMenu(title: title, at: index)
    }
}

参考

如果您的应用中使用了此库请告诉我或创建拉取请求 :)

@zigbang

MotionBook

作者

younatics Twitter

感谢

jegumhon

许可

YNDropDownMenu 在MIT许可证下可用。更多信息请参阅LICENSE文件。