Created
July 18, 2022 17:12
-
-
Save ashishkakkad8/747223d68f3675dce4f05e4396baec7e to your computer and use it in GitHub Desktop.
Prevent Screenshot of UIView - iOS
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
} | |
} | |
} |
how to use this on table view???
apple has warned not to use such methods of adding view's layer to another view's layer, this will break you UI. https://forums.developer.apple.com/forums/thread/722333
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@awnigharbia how?