-
-
Save 0xWDG/5ed15f3ca9d1505860669a481d952ada to your computer and use it in GitHub Desktop.
_UITextLayoutCanvasView
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
import UIKit | |
lazy var hiddenView: UIView = { | |
let hiddenView: UIView | |
// iOS 14.1 -> _UITextFieldCanvasView | |
// iOS 15.0 -> _UITextLayoutCanvasView | |
if let klass = NSClassFromString("_UITextFieldCanvasView") as? UIView.Type { | |
hiddenView = klass.init() | |
hiddenView.layer.perform(Selector(("setDisableUpdateMask:")), with: 0x12) | |
} else { | |
let textField = UITextField() | |
textField.isSecureTextEntry = true | |
hiddenView = textField.layer.sublayers?.first?.delegate as! UIView | |
hiddenView.subviews.forEach { $0.removeFromSuperview() } | |
} | |
addSubview(hiddenView) | |
hiddenView.translatesAutoresizingMaskIntoConstraints = false | |
NSLayoutConstraint.activate([ | |
hiddenView.leftAnchor.constraint(equalTo: leftAnchor), | |
hiddenView.rightAnchor.constraint(equalTo: rightAnchor), | |
hiddenView.topAnchor.constraint(equalTo: topAnchor), | |
hiddenView.bottomAnchor.constraint(equalTo: bottomAnchor) | |
]) | |
return hiddenView | |
}() | |
lazy var hiddenLabel: UILabel = { | |
let sublabel = UILabel() | |
hiddenView.addSubview(sublabel) | |
sublabel.translatesAutoresizingMaskIntoConstraints = false | |
NSLayoutConstraint.activate([ | |
sublabel.leftAnchor.constraint(equalTo: hiddenView.leftAnchor), | |
sublabel.rightAnchor.constraint(equalTo: hiddenView.rightAnchor), | |
sublabel.topAnchor.constraint(equalTo: hiddenView.topAnchor), | |
sublabel.bottomAnchor.constraint(equalTo: hiddenView.bottomAnchor) | |
]) | |
return sublabel | |
}() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi @nthnhung23,
It does not work on a whole screen, the screen will turn black if you try that.
What does work is:
Hope this helps :)