У меня проблема с цветом UITextField, который принадлежит UITableViewCell, когда он выбран.
Я изменил цвет выделения по умолчанию UITableViewCell, используя следующий код, который вызывается из AppDelegate при запуске приложения с параметрами:
UITableView.appearance().backgroundColor = backgroundColor
UITableViewCell.appearance().backgroundColor = backgroundColor
UITableViewCell.appearance().tintColor = tintColor
let colorView = UIView()
colorView.backgroundColor = ColorThemes.uiTableViewCellSelectedBackgroundColor
UITableViewCell.appearance().selectedBackgroundView = colorView
UITextField.appearance().textColor = ColorThemes.textColorNormal
UITextField.appearance().backgroundColor = ColorThemes.uiTextFieldBackgroundColor
UITextField.appearance().tintColor = UIColor.gray
UITextField.appearance().keyboardAppearance = ColorThemes.uiKeyboardAppearance
Этот код был взят из Интернета и одного из ответов StackOverflow.
Все нормально с нормальными ячейками с метками. Но у меня есть проблема с UITableViewCells, которые имеют UITextField внутри него. Когда ячейка была выбрана, она подсвечивается зеленым, и текстовое поле выглядит хорошо.
Но другие ячейки, которые были выбраны ранее (в выбранном состоянии), имеют проблему с цветом текстового поля. Это видно по картинкам ниже.
Я проверил иерархию пользовательского интерфейса и напечатал описание всех трех представлений, и все они имеют одинаковое описание:
Printing description of $30:
<_UITextFieldRoundedRectBackgroundViewNeue: 0x7fdeb209ac80; frame = (0 0; 70 30); opaque = NO; autoresize = W+H; userInteractionEnabled = NO; tintColor = UIExtendedGrayColorSpace 1 1; layer = <CALayer: 0x60000280d980>>
Printing description of $31:
<_UITextFieldRoundedRectBackgroundViewNeue: 0x7fdeaedb2b30; frame = (0 0; 70 30); opaque = NO; autoresize = W+H; userInteractionEnabled = NO; tintColor = UIExtendedGrayColorSpace 1 1; layer = <CALayer: 0x600002801180>>
Printing description of $32:
<_UITextFieldRoundedRectBackgroundViewNeue: 0x7fdeb209e090; frame = (0 0; 70 30); opaque = NO; autoresize = W+H; userInteractionEnabled = NO; tintColor = UIExtendedGrayColorSpace 1 1; layer = <CALayer: 0x60000287ac60>>