程序员swift开源库亮书房

Swift-仿微信QQ菜单,可高度自定义

2017-10-21  本文已影响360人  船长_
screenDemo.gif

PopupMenu是仿照YBPopupMenu所写的Swift版本,对原版本进行了适当的修改

使用说明:

method.png

使用示例:

    var popupMenu : PopupMenu?
    let TITLES = ["修改", "删除", "扫一扫","付款"]
    let ICONS = ["motify","delete","saoyisao","pay"]
    
    // block 无设置delegate
    @IBAction func topLeftBtnPopupMenueClick(_ sender: Any) {
     
        PopupMenu.showRelyOnView(view: sender as! UIView, titles: TITLES, icons: ICONS, menuWidth: 120, didSelectRow: { (index, value, popupMenu) in
            print("索引是: \(index)值是: \(value)")
        }) { (popupMenu) in
            popupMenu.backColor = UIColor.lightGray
            popupMenu.separatorColor = UIColor.white
            popupMenu.priorityDirection = PopupMenuPriorityDirection.none
            popupMenu.borderWidth = 1
            popupMenu.borderColor = UIColor.red
            popupMenu.rectCorner = [.bottomRight,.bottomLeft]
        }
    }

// 使用了代理和block混合
@IBAction func topRightBtnPopupMenueClick(_ sender: Any) {
        
        PopupMenu.showRelyOnView(view: sender as! UIView, titles: TITLES, icons: ICONS, menuWidth: 120, delegate: self) { (popupMenu) in
            popupMenu.priorityDirection = PopupMenuPriorityDirection.none
            popupMenu.borderWidth = 1
            popupMenu.borderColor = UIColor.red
           // popupMenu.rectCorner = [.bottomRight,.bottomLeft]
        }
   }

extension ViewController : PopupMenuDelegate{
    
    func popupMenuDidSelected(index: NSInteger, popupMenu: PopupMenu) {
        if popupMenu.tag == 111 {
            print(["111","222","333","444","555","666","777","888"][index])
        }else{
            print(TITLES[index])
        }
    }
}

需要高度自定义时候,可选代理方法

   @objc func popupMenuDidSelected(index : NSInteger,popupMenu: PopupMenu)
   @objc optional func popupMenuBeganDismiss()
   @objc optional func popupMenuDidDismiss()
   @objc optional func popupMenuBeganShow()
   @objc optional func popupMenudidShow()

Swift4PopupMenuDemo下载链接
Objective-CYBPopupMenu下载链接

上一篇下一篇

猜你喜欢

热点阅读