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.2.5
Convert Colors to Hex strings and vice versa, compare colors,... in a single line of code.
⭐️ 6
🕓 40 weeks ago
iOS macOS watchOS tvOS
.package(url: "https://github.com/NVMNovem/NVMColor_swift.git", from: "1.2.5")

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_swift", 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
}

Themed Color

You can get a color that fits the current device sheme if the input color is to close to the device scheme color.

struct MyView: View {
    @Environment(\.colorScheme) private var colorScheme
    
    var body: some View {
        Text("My custom text")
            .foregroundColor(Color(hex: "2E3240")!.themedColor(colorScheme))
    }
}

GitHub

link
Stars: 6
Last commit: 40 weeks ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

1.2.5
40 weeks ago

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