【Swift】UITextField 커서 숨기기 & 복사 붙여넣기를 불가능하게 하는 방법
3216 단어 iOSSwiftswift3XcodeUITextField
데모

절차
맞춤 클래스 만들기
먼저 UITextField의 커스텀 클래스를 만듭니다.
⌘+N에서 새 파일 만들기 화면으로 이동하여 Cocoa Touch Class를 선택하고 Next를 클릭합니다.

Subclass 설정
다음에 클래스명을 적당하게 입력(이번은 CustomeTextField로 했습니다.)하고, Subclass를 UITextField로 해, Next. 다음 화면에서 저장 위치를 선택하여 생성합니다.

코드
파일이 생기면 코드를 아래와 같이 기술해 갑니다.
CustomTextField.swiftimport UIKit
class CustomTextField: UITextField {
// 入力カーソル非表示
override func caretRect(for position: UITextPosition) -> CGRect {
return CGRect.zero
}
// 範囲選択カーソル非表示
override func selectionRects(for range: UITextRange) -> [Any] {
return []
}
// コピー・ペースト・選択等のメニュー非表示
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
return false
}
}
UITextField에 커스텀 클래스 적응
마지막으로 해당 TextField를 선택하고 Custome Class에 방금 만든 CustomTextField를 설정하여 완료합니다.
Reference
이 문제에 관하여(【Swift】UITextField 커서 숨기기 & 복사 붙여넣기를 불가능하게 하는 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/Simmon/items/f9d60ab51cc6b0b4b3bc
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
맞춤 클래스 만들기
먼저 UITextField의 커스텀 클래스를 만듭니다.
⌘+N에서 새 파일 만들기 화면으로 이동하여 Cocoa Touch Class를 선택하고 Next를 클릭합니다.

Subclass 설정
다음에 클래스명을 적당하게 입력(이번은 CustomeTextField로 했습니다.)하고, Subclass를 UITextField로 해, Next. 다음 화면에서 저장 위치를 선택하여 생성합니다.

코드
파일이 생기면 코드를 아래와 같이 기술해 갑니다.
CustomTextField.swift
import UIKit
class CustomTextField: UITextField {
// 入力カーソル非表示
override func caretRect(for position: UITextPosition) -> CGRect {
return CGRect.zero
}
// 範囲選択カーソル非表示
override func selectionRects(for range: UITextRange) -> [Any] {
return []
}
// コピー・ペースト・選択等のメニュー非表示
override func canPerformAction(_ action: Selector, withSender sender: Any?) -> Bool {
return false
}
}
UITextField에 커스텀 클래스 적응
마지막으로 해당 TextField를 선택하고 Custome Class에 방금 만든 CustomTextField를 설정하여 완료합니다.

Reference
이 문제에 관하여(【Swift】UITextField 커서 숨기기 & 복사 붙여넣기를 불가능하게 하는 방법), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/Simmon/items/f9d60ab51cc6b0b4b3bc텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)