This is about iOS 17 only. The only way I could hack around and achieve something like this was
- find the actual, real, border, get its real values
- sadly just add a fake on top of that layer once found, perfectly replicating it
so
///True™ iOS look of the border, and you can change the color
class FixedUITextField: UITextField {
var completed: Bool = true {
didSet {
fakeLayer.borderColor = completed ? rememberDefaultColor : UIColor.red.cgColor
}
}
private var rememberDefaultColor: CGColor? = UIColor.gray.cgColor
private lazy var fakeLayer: CALayer = {
let v = RepairedCALayer()
for found in layer.sublayers ?? [] {
if found.borderWidth > 0 {
layer.insertSublayer(v, above: found)
v.backgroundColor = found.backgroundColor
v.borderColor = found.borderColor
v.borderWidth = found.borderWidth
v.cornerRadius = found.cornerRadius
v.cornerCurve = found.cornerCurve
print("found and covered")
rememberDefaultColor = found.borderColor
return v
}
}
// defaults ICO disaster
v.backgroundColor = UIColor.systemBackground.cgColor
v.borderColor = UIColor.blue.cgColor
v.borderWidth = 1.0 / UIScreen.main.scale
v.cornerRadius = 4.0
v.cornerCurve = .circular
layer.addSublayer(v)
return v
}()
override func layoutSubviews() {
super.layoutSubviews()
fakeLayer.frame = bounds
}
}
This is about iOS 17 only. Am I missing something really obvious?
This is about iOS 17 only. Even more issues on this time waste …
-
for some reason I couldn’t find _UlTextFieldRoundedRectBackgroundViewNeue which appears to be the culprit. It’s right there in Xcode, click and see it, but I couldn’t find anything named that.
-
Bizarre: take my code above, instead of adding the fake layer, just change the color of the found layer. You’d think! I cannot for the life of me figure out where in the view cycle they set it. Any place I changed the color, “they” would change it back! The only way I could make it stick was with a timer, for goodness sake – give it a go.
This is about iOS 17 only. Am I missing something really obvious? – is there a way to change the border color of a UITextField as is?
If you are a new SO user or inexperienced programmer, please read this, thanks: don’t click “duplicate” due to the 100 ancient questions that have nothing to do with the subtlety asked here, thank you in advance.