import UIKit
import PDFKit
import CoreGraphics
class ViewController: UIViewController, UITextViewDelegate {
override func viewDidLoad() {
super.viewDidLoad()
let textview = nowTextView()
textview.frame = CGRect.init(x: 0, y: 300, width: 200, height: 100);
self.view.addSubview(textview)
textview.text = "这是测试"
textview.textColor = .black
textview.delegate = self
textview.isEditable = false
textview.tintColor = .clear
let menuController = UIMenuController.shared
let item1 = UIMenuItem(title: "测试1", action: #selector(ViewController.test))
let item2 = UIMenuItem(title: "测试2", action: #selector(ViewController.test))
menuController.menuItems = [item1, item2]
}
@objc func test() {
print("123456")
}
}
class nowTextView:UITextView {
open override func canPerformAction(_ action: Selector, withSender
sender: Any?) -> Bool {
//打印事件 想显示的 返回true
print(action)
if action == #selector(cut(_:)) {
return true
}
return false
}
}
效果图