美文网首页
SwiftUI(4)Color

SwiftUI(4)Color

作者: Z小新 | 来源:发表于2023-03-07 15:37 被阅读0次

    16进制颜色使用

     RoundedRectangle(cornerRadius: 10)
                .fill(Color.init(hex: 0x87CEEB))
                .frame(width: 300, height: 200)
    

    Color扩展方法

    extension Color {
        init(hex: Int, alpha: Double = 1) {
            let components = (
                R: Double((hex >> 16) & 0xff) / 255,
                G: Double((hex >> 08) & 0xff) / 255,
                B: Double((hex >> 00) & 0xff) / 255
            )
            self.init(
                .sRGB,
                red: components.R,
                green: components.G,
                blue: components.B,
                opacity: alpha
            )
        }
    }
    

    展示:


    image.png

    自定义颜色

    image.png

    设置名称,暗黑模式色值


    image.png

    使用:

    RoundedRectangle(cornerRadius: 10)
                .fill(Color("ColorThem"))
                .frame(width: 300, height: 200)
    

    展示:


    image.png image.png

    相关文章

      网友评论

          本文标题:SwiftUI(4)Color

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