Extension.swift 539 B

12345678910111213141516171819202122232425262728
  1. //
  2. // Extension.swift
  3. // fiveConstant
  4. //
  5. // Created by 李建 on 2023/1/31.
  6. //
  7. import Foundation
  8. import SwiftUI
  9. extension Color {
  10. init(hex: Int, alpha: Double = 1) {
  11. let components = (
  12. R: Double((hex >> 16) & 0xff) / 255,
  13. G: Double((hex >> 08) & 0xff) / 255,
  14. B: Double((hex >> 00) & 0xff) / 255
  15. )
  16. self.init(
  17. .sRGB,
  18. red: components.R,
  19. green: components.G,
  20. blue: components.B,
  21. opacity: alpha
  22. )
  23. }
  24. }