zoukankan      html  css  js  c++  java
  • 给文本标签UILabel添加长按复制功能

    http://www.111cn.net/sj/iOS/104236.htm

    http://blog.csdn.net/lrenjun/article/details/12582927

    自定义一个可复制的标签类,使其能够响应Touch事件并显示复制菜单。

    class CopyLabel: UILabel {
        override init(frame: CGRect) {
            super.init(frame: frame)
            userInteractionEnabled = true
            let longPress = UILongPressGestureRecognizer(target: self,
                                                         action: #selector(handleLongPress(_:)))
            addGestureRecognizer(longPress)
        }
        
        required init?(coder aDecoder: NSCoder) {
            fatalError("init(coder:) has not been implemented")
        }
        
        override func canBecomeFocused() -> Bool {
            return true
        }
        
        override func canPerformAction(action: Selector, withSender sender: AnyObject?) -> Bool {
            return action == #selector(NSObject.copy(_:))
        }
        
        override func copy(sender: AnyObject?) {
            let pBoard = UIPasteboard.generalPasteboard()
            pBoard.string = self.text
        }
        
        func handleLongPress(gesture: UILongPressGestureRecognizer) {
            self.becomeFirstResponder()
            let menu = UIMenuController.sharedMenuController()
            menu.setTargetRect(self.frame, inView: self)
            menu.setMenuVisible(true, animated: true)
        }
    }
  • 相关阅读:
    feign远程调用问题
    java8--stream
    feign业务组件远程请求 /oauth/token
    redis实现自增序列
    MySQL数据库 相关知识点
    netty
    spring的启动流程及bean的生命周期
    MethodHandleVS反射
    并发与并行
    关于注解的思考
  • 原文地址:https://www.cnblogs.com/argenbarbie/p/5795271.html
Copyright © 2011-2022 走看看