Skip to content

Instantly share code, notes, and snippets.

@KentarouKanno
Last active March 30, 2019 09:54
Show Gist options
  • Save KentarouKanno/edecb55ba78ba2c7399e6a00dca41e58 to your computer and use it in GitHub Desktop.
Save KentarouKanno/edecb55ba78ba2c7399e6a00dca41e58 to your computer and use it in GitHub Desktop.
  • テキストフィールドにフォーカスが入ったときにキャレット、メニューを出さないカスタムクラス
import UIKit

final class CustomTextField: UITextField {
    
    /* 入力キャレット非表示 */
    override func caretRect(for position: UITextPosition) -> CGRect {
        return .zero
    }
    /* 範囲選択カーソル非表示 */
    override func selectionRects(for range: UITextRange) -> [UITextSelectionRect] {
        return []
    }
    /* コピー・ペースト・選択等のメニュー非表示 */
    override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
        return false
    }
    
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment