美文网首页
Swift 动态颜色(亮色,暗色)

Swift 动态颜色(亮色,暗色)

作者: 假如兔子失了尾 | 来源:发表于2022-09-13 13:45 被阅读0次

RGB颜色

    /// 动态颜色
    /// - Parameter lightColor: lightMode Color
    /// - Parameter darkColor: darkMode Color
    static func dy_color(light: UIColor, dark: UIColor) -> UIColor {

        var color: UIColor = light

        if #available(iOS 13.0, *) {
            color = UIColor.init { (trainCollection: UITraitCollection) -> UIColor in
                if trainCollection.userInterfaceStyle == UIUserInterfaceStyle.dark {
                    // 黑暗模式
                    return dark
                }else {
                    // 其他模式
                    return light
                }
            }
        }

        return color
    }

16进制颜色

    /// 动态颜色(16进制)
    /// - Parameter lightColor: lightMode Color
    /// - Parameter darkColor: darkMode Color
    static func dy_color(light: Int, dark: Int) -> UIColor {

        var color = UIColor.gl_hex(hex: light)

        if #available(iOS 13.0, *) {
            color = UIColor.init { (trainCollection: UITraitCollection) -> UIColor in
                if trainCollection.userInterfaceStyle == UIUserInterfaceStyle.dark {
                    // 黑暗模式
                    return UIColor.gl_hex(hex: dark)
                }else {
                    // 其他模式
                    return UIColor.gl_hex(hex: light)
                }
            }
        }

        return color
    }

相关文章

网友评论

      本文标题:Swift 动态颜色(亮色,暗色)

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