Skip to content

Instantly share code, notes, and snippets.

@ashishkakkad8
Created July 18, 2022 17:12
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ashishkakkad8/747223d68f3675dce4f05e4396baec7e to your computer and use it in GitHub Desktop.
Save ashishkakkad8/747223d68f3675dce4f05e4396baec7e to your computer and use it in GitHub Desktop.
Prevent Screenshot of UIView - iOS
extension UIView {
func preventScreenshot() {
DispatchQueue.main.async {
let field = UITextField()
field.isSecureTextEntry = true
self.addSubview(field)
field.centerYAnchor.constraint(equalTo: self.centerYAnchor).isActive = true
field.centerXAnchor.constraint(equalTo: self.centerXAnchor).isActive = true
self.layer.superlayer?.addSublayer(field.layer)
field.layer.sublayers?.first?.addSublayer(self.layer)
}
}
}
@awnigharbia
Copy link

Thanks I managed to solve it.

@ashishkakkad8
Copy link
Author

ashishkakkad8 commented Oct 2, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment