Skip to content

Instantly share code, notes, and snippets.

@damian-rzeszot
Last active February 9, 2024 10:40
Show Gist options
  • Save damian-rzeszot/bbfd92895dfe9400ba9a7cf2a0c1e670 to your computer and use it in GitHub Desktop.
Save damian-rzeszot/bbfd92895dfe9400ba9a7cf2a0c1e670 to your computer and use it in GitHub Desktop.
_UITextLayoutCanvasView
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
}()
}
@Joseph-Nathan
Copy link

please, can we used this to hidden full app view ?
how to add this to AppDelegate ?
thanks a lot.

@markst
Copy link

markst commented Jul 21, 2022

@damian-rzeszot thanks for this. how does setDisableUpdateMask play into this & how were you able to figure?

@drspoton
Copy link

@Joseph-Nathan it is private API, you app won't pass Apple's review

@nthnhung23
Copy link

@damian-rzeszot I want to prevent taking navigation bar. Could you give me a hand to resolve this issue? Many thanks!

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