Swiftpack.co - NVMNovem/NVMColor_swift as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by NVMNovem.
NVMNovem/NVMColor_swift 1.1.0
Convert Colors to Hex strings and vice versa, compare colors,... in a single line of code.
⭐️ 2
🕓 4 days ago
iOS macOS
.package(url: "https://github.com/NVMNovem/NVMColor_swift.git", from: "1.1.0")

NVMColor_header

iOS · macOS · watchOS · tvOS


A pure Swift library that allows you to easily convert SwiftUI Colors to Hex String and vice versa.

This framework extends the Color, UIColor and NSColor types. Depending on the target version, you have the same functions as SwifUI's Color.

This project is created and maintained by Novem.


Installation

Swift Package Manager

You can use The Swift Package Manager (SPM) to install NVMRegion by adding the following description to your Package.swift file:

import PackageDescription

let package = Package(
    name: "YOUR_PROJECT_NAME",
    dependencies: [
        .package(url: "https://github.com/NVMNovem/NVMColor", from: "1.0.0"),
    ]
)

Then run swift build.

You can also install using SPM in your Xcode project by going to "Project->NameOfYourProject->Swift Packages" and placing "https://github.com/NVMNovem/NVMColor" in the search field. Then select the option that is most suited for your needs.

Usage Guide

Hex string to Color

let color = Color(hex: "159F84")

Color to Hex string

let hexColor = Color.green.hex

Compare 2 Colors

Non valid comparisson

if Color.green.isEqual(to: .red) {
   //Will not be executed
}

Non valid comparisson using tolerance

if Color.green.isEqual(to: .red, tolerance: 0.5) {
   //Will not be executed
}

Valid comparisson

if Color.green.isEqual(to: Color(hex: "34C759")) {
   //Will be executed
}

Valid comparisson using tolerance

if Color.green.isEqual(to: Color(hex: "34C759"), tolerance: 0.5) {
   //Will be executed
}

You can also compare by using the NVMColor function.

if NVMColor.colorsAreEqual(.green, to: Color(hex: "34C759")) {
   //Will be executed
}

GitHub

link
Stars: 2
Last commit: 4 days ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Release Notes

1.1.0
4 days ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics