Skip to content

Latest commit

 

History

History
44 lines (34 loc) · 1.23 KB

File metadata and controls

44 lines (34 loc) · 1.23 KB

ColorHex

Static Badge

ColorHex is a simple package for Swift apps. It allows you to easily work with hex codes in your app.

Installation

To install with Swift Package Manager, add the following as a dependency to your Package.swift:

dependencies: [
    .package(url: "https://github.com/CaedmonMyers/ColorHex.git", from: "1.0.1")
]

Alternatively, you can install the package by downloading the ColorHex.swift and adding it to your project.

Usage

Show a color view from a hex string:

import ColorHex

struct ContentView: View {
    var body: some View {
        Color(hex: "FFFFFF")
    }
}

Use .toHex() with a color picker:

ColorPicker("Color Picker", selection: $color)
.onChange(of: color) { oldValue, newValue in
let uiColor = UIColor(newValue)
let hexString = uiColor1.toHex()

spaces[selectedSpaceIndex].startHex = hexString
}

Functions

  • Color(hex: "FFFFFF"): View
  • .toHex(): String?

You will need to properly handle the optional value for the .toHex() function in the event the conversion fails.