Skip to content

Instantly share code, notes, and snippets.

@TuenTuenna
Created September 3, 2021 07:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TuenTuenna/d2420fc7c874ff7f3a74a9bf773e0726 to your computer and use it in GitHub Desktop.
Save TuenTuenna/d2420fc7c874ff7f3a74a9bf773e0726 to your computer and use it in GitHub Desktop.
SwiftUi HexCode 로 Color 가져오기

SwiftUi 에서 HexCode 로 색 가져오기 Extension 입니다

// hex 코드를 사용하기 위한 Color Extension
extension Color {
    init(hex: UInt, alpha: Double = 1) {
        self.init(
            .sRGB,
            red: Double((hex >> 16) & 0xff) / 255,
            green: Double((hex >> 08) & 0xff) / 255,
            blue: Double((hex >> 00) & 0xff) / 255,
            opacity: alpha
        )
    }
}

사용 예시

SomeView().background(Color.init(Oxffffff))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment