自定义UI控件:禁止输入框的功能

  1. 禁止了输入框的所有操作
// 入力ボックスのすべての機能を無効にします
class UnavailableField: UITextField {
    override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
        return super.canPerformAction(action, withSender: sender)
    }
}

  1. 可选择性的禁止输入框的部分操作
// 入力ボックスの各機能を無効にします 
class EachUnavailableField: UITextField {
    override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
    	// カッド
        if action == #selector(cut(_:)) {
            return false
        }
        // コーピ
        if action == #selector(copy(_:)) {
            return false
        }
        // 貼り付け
        if action == #selector(paste(_:)) {
            return false
        }
        // 選択
        if action == #selector(select(_:)) {
            return false
        }
        // すべて選択
        if action == #selector(selectAll(_:)) {
            return false
        }
        return super.canPerformAction(action, withSender: sender)
    }
}

发布了4 篇原创文章 · 获赞 0 · 访问量 79

猜你喜欢

转载自blog.csdn.net/weixin_42163902/article/details/104073264
今日推荐