I need more information about what you mean by "doesn't work".
Did you check each UITraitEnvironment‘s traitCollection?
Or is your color or image not changing automatically?
Or are you using cgColor or another non-dynamic property and it doesn’t update automatically?
For now, I can recommend the following solution.
let traitCollection = UITraitCollection(userInterfaceStyle: .dark)
myChildView.overrideUserInterfaceStyle = traitCollection.userInterfaceStyle
traitCollection.performAsCurrent {
myChildView.backgroundColor = .systemBackground
myChildView.layer.borderWidth = 10
myChildView.layer.borderColor = UIColor.systemBackground.cgColor
}