- Xcode 9.0 +
- iOS 11.0 or greater
- Install CocoaPods
- Add this repo to your
Podfile
platform :ios, '11.0'
target 'ProjectName' do
use_frameworks!
pod 'KActionMenu'
end
- Run
pod install
- Open up the new
.xcworkspace
that CocoaPods generated - Whenever you want to use the library:
import KActionMenu
- Simply download the
KActionMenu
source files and import them into your project.
import UIKit
class ViewController: UIViewController {
@IBOutlet weak var bgImageView: UIImageView!
var menu:KActionMenu!
override func viewDidLoad() {
super.viewDidLoad()
bgImageView.addGestureRecognizer(UILongPressGestureRecognizer(target: self, action: #selector(longPressAction)))
menu = KActionMenu(rootView: self.view) // 1.
menu.view.table.actionDelegate = self
menu.view.screenDelegate = self
menu.setMenuStyle(.light) // .light, .dark
}
@objc func longPressAction(gesture: UILongPressGestureRecognizer) {
let location = gesture.location(in: bgImageView)
menu.show(items: [("Follow", UIImage(named: "add")), ("Camera", UIImage(named: "cam")), ("Share", UIImage(named: "share")), ("Like", UIImage(named: "like"))], position: CGPoint(x: location.x, y: location.y), animation: .scale) // 2.
}
}
extension ViewController: KActionDelegate, KActionScreenDelegate {
func didCloseScreen() {
print(" - Closed - ")
}
func touchItem(name: String, index: Int) {
print(name, index)
self.menu.view.close()
}
}
Usage is provided under the MIT License. See LICENSE for the full details.