UILabel in UITableViewCell in .xib file ignores Dark Mode

@Andrew Bennet this worked for me. Thank you. I had to implement the work around in Objective-C because this part of my application is still in Objective-C.

- (void)awakeFromNib {
    [super awakeFromNib];
    if (@available(iOS 13.0, *)) {
        // The label's textColor was set to secondaryLabel in the XIB editor
        // but we reassign it to secondaryLabel again here. This prevents
        // a bug where the label always appears in its light mode variant.
//        label.textColor = .secondaryLabel
        lblTitle.textColor = UIColor.secondaryLabelColor;
    }
}

This seems to be a bug in Xcode 11 (tested in beta 7 and GM Seed 1) - I have filed this issue with Apple via Feedback Assistant (FB7198213). The issue is fixed in Xcode 11 GM Seed 2.

For previous versions of Xcode 11, a workaround for the incorrect behaviour of dynamic label colors is to reassign the label color in awakeFromNib() in the table view cell subclass. E.g.:

class TableCell: UITableViewCell {

    @IBOutlet private weak var label: UILabel!

    override func awakeFromNib() {
        super.awakeFromNib()
        if #available(iOS 13.0, *) {
            // The label's textColor was set to secondaryLabel in the XIB editor
            // but we reassign it to secondaryLabel again here. This prevents
            // a bug where the label always appears in its light mode variant.
            label.textColor = .secondaryLabel
        }
    }
}

Original answer: This original answer addresses the issue only for the default (i.e. primary) label color

There seems to be a bug in the XIB editor in Xcode 11 (tested in beta 7) with regards to editing label colours. When a label color is set in the XIB editor to "Label Color" (even if it was already set to that), the underlying XML is modified in a way which results in the label appearing black even in dark mode. Examining the diff of a XIB file between the creation of a new label, and after explicitly setting that label's color to "Label Color", one can see the difference.

For my simple example, the XIB file's XML went from:

<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Text here" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="VKH-gX-gtO">
   <rect key="frame" x="20" y="15" width="71" height="21"/>
   <fontDescription key="fontDescription" type="system" pointSize="17"/>
   <nil key="textColor"/>
   <nil key="highlightedColor"/>
</label>

to:

<label opaque="NO" userInteractionEnabled="NO" contentMode="left" horizontalHuggingPriority="251" verticalHuggingPriority="251" text="Text here" textAlignment="natural" lineBreakMode="tailTruncation" baselineAdjustment="alignBaselines" adjustsFontSizeToFit="NO" translatesAutoresizingMaskIntoConstraints="NO" id="VKH-gX-gtO">
   <rect key="frame" x="20" y="15" width="71" height="21"/>
   <fontDescription key="fontDescription" type="system" pointSize="17"/>
   <nil key="highlightedColor"/>
</label>

Note that the line <nil key="textColor"/> was removed. Manually adding this back fixes the behaviour of the label in dark mode.


Similar problem here. Some dynamic colors used in XIBs do not use their dark version when dark mode is enabled.

This happens both in the Simulator and on real devices. Colors do appear correctly when simulating dark mode within Xcode (Interface Builder).

My project deployment target is iOS 10.


Xcode 11 GM Seed 2 which was released today seems fixed the problem.

From release note:

Fixed an issue where system colors in XIB files set to deploy before iOS 13.0 wouldn’t adapt to the system appearance at runtime. (54362252)