YYText中YYLabel和YYTextView适配暗黑模式

YYTextView 和YYLabel 适配暗黑模式完美解决的前提是 UIColor 必须正确适配

NSMutableAttributedString中必须要传NSForegroundColorAttributeName,适配好颜色


YYLabel.m 添加如下代码

#pragma mark - DarkMode Adapater

#ifdef __IPHONE_13_0

- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection{

    [super traitCollectionDidChange:previousTraitCollection];

    if (@available(iOS 13.0, *)) {

        if([UITraitCollection.currentTraitCollection hasDifferentColorAppearanceComparedToTraitCollection:previousTraitCollection]){

            [self.layer setNeedsDisplay];

        }

    } else {

        // Fallback on earlier versions

    }

}

#endif

YYTextView.m 添加如下代码

#pragma mark - Dark mode Adapter

#ifdef __IPHONE_13_0

- (void)traitCollectionDidChange:(UITraitCollection *)previousTraitCollection{

    [super traitCollectionDidChange:previousTraitCollection];

    if (@available(iOS 13.0, *)) {

        if([UITraitCollection.currentTraitCollection hasDifferentColorAppearanceComparedToTraitCollection:previousTraitCollection]){

            [self _commitUpdate];

        }

    } else {

        // Fallback on earlier versions

    }

}

#endif

你可能感兴趣的:(YYText中YYLabel和YYTextView适配暗黑模式)