All Projects → soffes → Color

soffes / Color

Licence: mit
Color utilities for macOS, iOS, tvOS, and watchOS

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Color

Datez
📆 Breeze through Date, DateComponents, and TimeInterval with Swift!
Stars: ✭ 254 (+75.17%)
Mutual labels:  tvos, watchos, cocoapods, carthage
Xcglogger
A debug log framework for use in Swift projects. Allows you to log details to the console (and optionally a file), just like you would have with NSLog() or print(), but with additional information, such as the date, function name, filename and line number.
Stars: ✭ 3,710 (+2458.62%)
Mutual labels:  tvos, watchos, cocoapods, carthage
Web3.swift
A pure swift Ethereum Web3 library
Stars: ✭ 295 (+103.45%)
Mutual labels:  tvos, watchos, cocoapods, carthage
Swiftlinkpreview
It makes a preview from an URL, grabbing all the information such as title, relevant texts and images.
Stars: ✭ 1,216 (+738.62%)
Mutual labels:  tvos, watchos, cocoapods, carthage
Ducttape
📦 KeyPath dynamicMemberLookup based syntax sugar for Swift.
Stars: ✭ 138 (-4.83%)
Mutual labels:  tvos, watchos, cocoapods, carthage
Columbus
A feature-rich country picker for iOS, tvOS and watchOS.
Stars: ✭ 23 (-84.14%)
Mutual labels:  tvos, watchos, carthage, spm
Contentful.swift
A delightful Swift interface to Contentful's content delivery API.
Stars: ✭ 132 (-8.97%)
Mutual labels:  tvos, watchos, cocoapods, carthage
Cdmarkdownkit
An extensive Swift framework providing simple and customizable markdown parsing.
Stars: ✭ 158 (+8.97%)
Mutual labels:  tvos, watchos, cocoapods, carthage
Swifterswift
A handy collection of more than 500 native Swift extensions to boost your productivity.
Stars: ✭ 10,706 (+7283.45%)
Mutual labels:  tvos, watchos, cocoapods, carthage
Guitar
A Cross-Platform String and Regular Expression Library written in Swift.
Stars: ✭ 641 (+342.07%)
Mutual labels:  tvos, watchos, cocoapods, carthage
Iso8601
ISO8601 date parser and writer
Stars: ✭ 213 (+46.9%)
Mutual labels:  tvos, watchos, cocoapods, carthage
Sdwebimagewebpcoder
A WebP coder plugin for SDWebImage, use libwebp
Stars: ✭ 101 (-30.34%)
Mutual labels:  tvos, watchos, cocoapods, carthage
L10n Swift
Localization of the application with ability to change language "on the fly" and support for plural form in any language.
Stars: ✭ 177 (+22.07%)
Mutual labels:  tvos, watchos, cocoapods, carthage
Swiftyattributes
A Swifty API for attributed strings
Stars: ✭ 1,303 (+798.62%)
Mutual labels:  tvos, watchos, cocoapods, carthage
Cocoalumberjack
A fast & simple, yet powerful & flexible logging framework for Mac and iOS
Stars: ✭ 12,584 (+8578.62%)
Mutual labels:  tvos, watchos, cocoapods, carthage
Functionkit
A framework for functional types and operations designed to fit naturally into Swift.
Stars: ✭ 302 (+108.28%)
Mutual labels:  tvos, watchos, cocoapods, carthage
Swiftframeworktemplate
A template for new Swift iOS / macOS / tvOS / watchOS Framework project ready with travis-ci, cocoapods, Carthage, SwiftPM and a Readme file
Stars: ✭ 527 (+263.45%)
Mutual labels:  tvos, watchos, cocoapods, carthage
Swiftysound
SwiftySound is a simple library that lets you play sounds with a single line of code.
Stars: ✭ 995 (+586.21%)
Mutual labels:  tvos, cocoapods, carthage, spm
Sqift
Powerful Swift wrapper for SQLite
Stars: ✭ 119 (-17.93%)
Mutual labels:  tvos, watchos, cocoapods, carthage
Sheeeeeeeeet
Sheeeeeeeeet is a Swift library for creating menus, custom action sheets, context menus etc.
Stars: ✭ 1,177 (+711.72%)
Mutual labels:  cocoapods, carthage, spm

Color

Version Build Status Swift Version Carthage compatible

Color utilities in pure Swift for macOS, iOS, watchOS, and tvOS. Color supports Carthage and Swift Package Manager. It is also tested on Linux.

Color was abstracted from Contrast, a macOS app for checking designs for accessible color combinations.

Installation

Carthage

Add the following to your Cartfile:

github "soffes/Color"

Swift Package Manager

Add the following to your dependencies in your Package.swift:

.package(url: "https://github.com/soffes/Color.git", from: "0.1.1")

Usage

Color provides structs for different color models. Currently only RGB and HSL are supported. Most color calculations are specific to a color model. For example, darkening a color is only available for HSL colors and not RGB colors. If you'd like to darken an RGB color, you’ll need to convert to HSL first. Here’s an example:

let rgb = RGBColor(red: 1, green: 0, blue: 0)
let hsl = HSLColor(rgb: rgb)
let darkerRed = hsl.darkening()

Note that Color’s structs don’t support alpha since that isn’t used in any of the color calculations. This may be added in the future.

Hex conversions are only available for RGB colors.

let rgb = RGBColor(hex: "0f0")!
rgb.hex // "00ff00"

NSColor & UIColor

There are convenience methods on NSColor & UIColor if you are working in a Cocoa application. Each color model (RGBColor, HSLColor, etc.) has an extension for SystemColorType which is either NSColor or UIColor depending on the platform. Here's a few examples:

UIColor.red.darkening()
UIColor.green.desaturating()
NSColor.blue.isDark

WCAG

RGB colors also have WCAG 2.0 calculations. First, calculate a contrast ratio:

let color1 = RGBColor(red: 170.0 / 255.0, green: 204.0 / 255.0, blue: 1)
let color2 = RGBColor(red: 34.0 / 255.0, green: 34.0 / 255.0, blue: 51.0 / 255.0)
let contrastRatio = color1.contrastRatio(to: color2) // 9.51

Now, you can check the conformance level:

ConformanceLevel(contrastRatio: contrastRatio) // .aaa

Thanks

Thanks to color & color-convert for inspiration.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].