美文网首页
iOS适配深色模式

iOS适配深色模式

作者: 小羊爱学习 | 来源:发表于2022-06-28 14:49 被阅读0次

1.如果你的项目之前禁用了深色模式,在plist中请删除这一项


image.png
  1. UIColor
    iOS13中系统提供了动态颜色的方法:
+ (UIColor *)colorWithDynamicProvider:(UIColor * (^)(UITraitCollection *traitCollection))dynamicProvider API_AVAILABLE(ios(13.0), tvos(13.0)) API_UNAVAILABLE(watchos);
- (UIColor *)initWithDynamicProvider:(UIColor * (^)(UITraitCollection *traitCollection))dynamicProvider API_AVAILABLE(ios(13.0), tvos(13.0)) API_UNAVAILABLE(watchos);

给UIColor 增加一个分类

+(UIColor *)colorWithDarkModeColor:(UIColor *)darkColor normalColor:(UIColor *)color{
    if (@available(iOS 13.0,*)) {
        if (darkColor) {
            UIColor *dyColor = [UIColor colorWithDynamicProvider:^UIColor * _Nonnull(UITraitCollection * _Nonnull trainCollection) {
                if ([trainCollection userInterfaceStyle] == UIUserInterfaceStyleDark) {
                    return darkColor;
                }
                else {
                    return color;
                }
            }];
            return dyColor;
        }
        return color;
    }
    return color;
}

相关文章

  • iOS13-适配夜间模式/深色外观(Dark Mode)

    iOS13-适配夜间模式/深色外观(Dark Mode) iOS13-适配夜间模式/深色外观(Dark Mode)

  • uni-app做iOS的夜间模式

    iOS13适配暗黑模式/夜间模式/深色模式/暗黑主题(DarkMode)问题:1.监听Android深色或浅色模式...

  • iOS适配深色模式

    iOS13出来已经挺久了,今天才认真的看了看深色模式的魅力,老工程适配深色模式的确会是个庞大的工程,这篇文章记录一...

  • iOS适配深色模式

    1.如果你的项目之前禁用了深色模式,在plist中请删除这一项 UIColoriOS13中系统提供了动态颜色的方法...

  • iOS深色模式适配

    不适配深色模式 直接在info新加一个字段 User Interface Style 设置值为 Light 适配深...

  • iOS适配深色模式

    我们所熟悉的 UIView 、UIViewController 、UIScreen、UIWindow 都已经遵从了...

  • iOS 深色模式的适配

    你可以这样玩 也可这样玩 如果是在ViewController 里面 还可以这样玩 颜色适配 还可以这么玩 ,用A...

  • iOS适配深色DarkMode模式

    iOS在13的版本加入了对深色模式的支持,深色模式下App整体上呈现黑色UI界面,现在许多App都完成了深色模式的...

  • Sign In with Apple

    原文博客地址: Sign In With Apple 在之前的文章iOS13适配深色模式(Dark Mode)中只...

  • ios 不想适配ios13暗黑模式怎么办? Xcode10打包适

    前言:ios13可以设置暗黑模式,即浅色和深色,但是app如果适配的话需要做很多工作,比如暗黑图片等,如果不想适配...

网友评论

      本文标题:iOS适配深色模式

      本文链接:https://www.haomeiwen.com/subject/xietyhtx.html