What is the default background color of UITableViewCell in iOS 13?
Cells in a plain styled table view use UIColor.systemBackground[Color]
for their background, UIColor.label[Color]
for the title text, and UIColor.secondaryLabel[Color]
for the subtitle text.
For a grouped style table view, the cell background uses UIColor.secondarySystemGroupedBackground[Color]
and the table view background uses UIColor.systemGroupedBackground[Color]
.
All of these adapt to light/dark mode.
Below is a helpful UIColor extension that allows you to print the light and dark description of any color.
extension UIColor {
var lightDarkDescription: String {
let lightTraits = UITraitCollection.init(userInterfaceStyle: .light)
let darkTraits = UITraitCollection.init(userInterfaceStyle: .dark)
let lightColor = self.resolvedColor(with: lightTraits)
let darkColor = self.resolvedColor(with: darkTraits)
if lightColor == darkColor {
return self.description
} else {
return "\(self), light: \(lightColor), dark: \(darkColor)"
}
}
}
Examples:
print(UIColor.secondarySystemGroupedBackground.lightDarkDescription)
print(UIColor.secondaryLabel.lightDarkDescription)
print(UIColor.green.lightDarkDescription)
Output:
<UIDynamicSystemColor: 0x6000005a5d80; name = secondarySystemGroupedBackgroundColor>, light: UIExtendedGrayColorSpace 1 1, dark: UIExtendedSRGBColorSpace 0.109804 0.109804 0.117647 1
<UIDynamicSystemColor: 0x6000005a5f00; name = secondaryLabelColor>, light: UIExtendedSRGBColorSpace 0.235294 0.235294 0.262745 0.6, dark: UIExtendedSRGBColorSpace 0.921569 0.921569 0.960784 0.6
UIExtendedSRGBColorSpace 0 1 0 1
If anyone wants to play with all of the colors, see my SystemColors demo app on GitHub.
In iOS 13, to support dark mode, you can use secondarySystemGroupedBackground
for the cell background.
The Swift code:
if #available(iOS 13.0, *) {
cellBackgroundColor = .secondarySystemGroupedBackground
} else {
cellBackgroundColor = .white
}
Correspondingly, for group table view background, you can use (primary) systemGroupedBackground
.
The new semantic colors are for groups, containing other groups (primary -> secondary -> tertiary), and not limiting to table views. It makes perfect sense. I wrote about it here.