swiftui-color

2.0.0

FluidGroup/swiftui-color

What's New

2.0.0

2023-05-08T14:46:56Z

What's Changed

New Contributors

  • @muukii made their first contribution in #1

Full Changelog: 1.0.0...2.0.0

SwiftUI Color Hex API

This API provides extensions to SwiftUI's Color struct to easily create colors from hexadecimal strings or integers.

Color Initializer from Hex String

public init(
  _ colorSpace: Color.RGBColorSpace = .sRGB,
  hexString: String
)

This initializer creates a Color instance from a hexadecimal string.

Parameters

  • colorSpace: The RGB color space to use for the color. Default value is .sRGB.
  • hexString: A string representing the color in hexadecimal format. The string can optionally include a '#' prefix.

Usage

let color = Color(hexString: "#FF5733")

Color Initializer from Hex Integer

public init(
  _ colorSpace: Color.RGBColorSpace = .sRGB,
  hexInt: Int,
  opacity: CGFloat = 1
)

This initializer creates a Color instance from a hexadecimal integer.

Parameters

  • colorSpace: The RGB color space to use for the color. Default value is .sRGB.
  • hexInt: An integer representing the color in hexadecimal format.
  • opacity: The opacity of the color. Default value is 1.

Usage

let color = Color(hexInt: 0xFF5733)

These extensions make it convenient to work with colors in a SwiftUI project when using hexadecimal values for color definitions.

Description

  • Swift Tools 5.6.0
View More Packages from this Author

Dependencies

  • None
Last updated: Wed Apr 03 2024 14:32:22 GMT-0900 (Hawaii-Aleutian Daylight Time)