• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
飞鸿518
博客园    首页    新随笔    联系   管理    订阅  订阅

swift textview禁止用户使用复制粘贴

//自定义一个TextView

class Own_TextView: UITextView {

    override func caretRect(for position: UITextPosition) -> CGRect {

        return CGRect.zero

    }

    override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {

        if action == #selector(copy(_:)) || action == #selector(selectAll(_:)) {

            return false

        }

        if action == #selector(paste(_:)){

            return false

        }

        return super.canPerformAction(action, withSender: sender)

    }

}

//禁止复制粘贴

  override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {

       return false

 }

let textView = Own_TextView.init(frame: CGRect(x:5, y: NavigationBarHeight + 20, width: ScreenWidth - 10, height: screenHeight - NavigationBarHeight-398-20))

posted @ 2018-04-02 12:30  飞鸿518  阅读(504)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3