Swift-仿微信QQ菜单,可高度自定义
2017-10-21 本文已影响360人
船长_
screenDemo.gif
PopupMenu
是仿照YBPopupMenu所写的Swift版本,对原版本进行了适当的修改
使用说明:
-
PopupMenu
使用类方法调用 -
PopupMenu
提供代理 block 代理和block混合使用,总共对外开放了六个接口生成实例,推荐使用block -
PopupMenu
不出意外,应该会有bug未发现,如有发现,请自行解决
使用示例:
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下载链接