Is it called in layoutSubviews to support dark mode. layoutSubviews is called on all views when the system dark mode setting is turned on or off. The colour specified have a light and dark variety.Removing the textRect and editingRect does not stop the issue. If I remove the lineself.textColor = .textFieldText The crash doesn not occur, so it seems this line is causing an issue.I recreate it by having two text fields and;- focus on first text field and type a letter- focus on second text field and type a letter- attempt to focus on the first text field - at this point layoutSubviews goes into an infinite loop.
Post
Replies
Boosts
Views
Activity
No attributes strings in this case. I've added the code below for the complete subclass. This code doesn't crash at all on iOS 13.It crashes *sometimes* on iOS 11 and 12 simulators with layoutSubviews in an infinite loop. Note it doesn't crash immediately or on first load. Sometimes it will take a couple of clicks within the text box or some letters being typed.import UIKit
class FormTextField: UITextField {
// MARK: Layout overrides
override func textRect(forBounds bounds: CGRect) -> CGRect {
return CGRect(x: bounds.origin.x + 10, y: bounds.origin.y, width: bounds.width + 10, height: bounds.height)
}
override func editingRect(forBounds bounds: CGRect) -> CGRect {
return CGRect(x: bounds.origin.x + 10, y: bounds.origin.y, width: bounds.width + 10, height: bounds.height)
}
// MARK: Private properties
private var hintText: String?
// MARK: Life Cycle
init(hintText: String? = nil) {
super.init(frame: .zero)
self.autocapitalizationType = .none
self.autocorrectionType = .no
self.spellCheckingType = .no
self.font = UIFont.font(type: .helveticaNeueRegular, size: 15)
self.layer.borderColor = UIColor.mswGrayLight.cgColor
self.layer.borderWidth = 0.5
self.layer.cornerRadius = 2
self.hintText = hintText
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func layoutSubviews() {
super.layoutSubviews()
styleViews()
}
// MARK: Theme Support
private func styleViews() {
self.layer.borderColor = UIColor.textAreaOutline.cgColor
self.tintColor = .mswLightBlue
self.textColor = .textFieldText
}
}