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) | |
} | |
} | |
} |
Author
ashishkakkad8
commented
Oct 2, 2023
via email
If you found anything please post it in this thread.
Thank you.
…On Sun, Oct 1, 2023, 3:00 PM Awni Gharbia ***@***.***> wrote:
***@***.**** commented on this gist.
------------------------------
Thanks I managed to solve it.
—
Reply to this email directly, view it on GitHub
<https://gist.github.com/ashishkakkad8/747223d68f3675dce4f05e4396baec7e#gistcomment-4709935>
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABUV4AOCDXBSIUFDMCCVVBTX5EZ2TBFKMF2HI4TJMJ2XIZLTSKBKK5TBNR2WLJDHNFZXJJDOMFWWLK3UNBZGKYLEL52HS4DFQKSXMYLMOVS2I5DSOVS2I3TBNVS3W5DIOJSWCZC7OBQXE5DJMNUXAYLOORPWCY3UNF3GS5DZVRZXKYTKMVRXIX3UPFYGLK2HNFZXIQ3PNVWWK3TUUZ2G64DJMNZZDAVEOR4XAZNEM5UXG5FFOZQWY5LFVEYTCNZUGE2DIMJRU52HE2LHM5SXFJTDOJSWC5DF>
.
You are receiving this email because you authored the thread.
Triage notifications on the go with GitHub Mobile for iOS
<https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675>
or Android
<https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub>
.
@awnigharbia how?
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