Swiftpack.co - mtynior/Felucia as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by mtynior.
mtynior/Felucia 1.5.4
UIColor extensions written in Swift
⭐️ 5
🕓 4 years ago
.package(url: "https://github.com/mtynior/Felucia.git", from: "1.5.4")

#Felucia Build Status Swift 3.0 License CocoaPods Carthage

Felucia provides useful extensions to UIColor.



Project is no longer maintained!



Requirements

  • iOS 9.0+ / tvOS 9.0+ / watchOS 2.0+
  • Xcode 8+

Integration

CocoaPods

You can use CocoaPods to install Felucia by adding it to your Podfile:

platform :ios, '9.0'
use_frameworks!

target 'MyApp' do
	pod 'Felucia'
end

Run pods install to intagrate pods with your project.

Carthage

You can use Carthage to install Felucia by adding it to your Cartfile:

github "mtynior/Felucia"

Run carthage update to build the framework and drag the built Felucia.framework into your Xcode project.

Swift Package Managers (SPM)

You can use The Swift Package Manager to install Felucia by adding it to your Package.swift file:

import PackageDescription

let package = Package(
    name: "MyApp",
    targets: [],
    dependencies: [
        .Package(url: "https://github.com/mtynior/Felucia.git", majorVersion: 1)
    ]
)

Manually

You can also manually add Felucia to you project:

  1. Download Felucia.swift file,
  2. Drag Felucia.swift into you project's tree.

Usage

Color initialization

Hex ARGB string

UIColor(hexARGB: "#fff")
UIColor(hexARGB: "fff")
UIColor(hexARGB: "#e2f5d3")
UIColor(hexARGB: "e2f5d3")
UIColor(hexARGB: "#ffe2f5d3")
UIColor(hexARGB: "ffe2f5d3")

RGBA

UIColor(r: 255, g: 128, b: 64, a: 255)
UIColor(r: 255, g: 128, b: 64)

UIColor(red: 1.0, green: 0.5, blue: 0.25, alpha: 1.0)
UIColor(red: 1.0, green: 0.5, blue: 0.25)

CMYK

UIColor(cyan: 0, magneta: 0.5, yellow: 0.75, black: 0.498)

HSLA

The h can be set as value in [0, 1] or [0, 360].

The s can be set as value in l are in [0, 1] or [0, 100].

The a can be set as value in [0, 1].

UIColor(h: 157.0, s: 24, l: 51)
UIColor(h: 0.436, s: 0.24, l: 0.51)
UIColor(h: 0.436, s: 0.24, l: 0.51, a: 1.0)

Retrieving color components

UIColor(r: 255, g: 128, b: 64, a: 255).rgba() // (r: 255, g: 128, b: 64, a: 255)
UIColor(r: 255, g: 128, b: 64, a: 255).rgbaArray() // [255, 128, 64, 255]

UIColor(r: 255, g: 128, b: 64, a: 255).rgbaf() // (r: 1.0, g: 0.5, b: 0.25, a: 1.0)
UIColor(r: 255, g: 128, b: 64, a: 255).rgbafArray() // [1.0, 0.5, 0.25, 1.0]

UIColor(r: 255, g: 128, b: 64, a: 255).hsba() // (h: 0.056, s: 0.749, b: 1.0, a: 1.0)
UIColor(r: 255, g: 128, b: 64, a: 255).hsbaArray() // [0.056, 0.749, 1.0, 1.0]

UIColor(r: 255, g: 128, b: 64, a: 255).hsla() // (h: 0.0558464, s: 1.0, l: 0.62549, a: 1.0)
UIColor(r: 255, g: 128, b: 64, a: 255).hslaArray() // [0.0558464, 1.0, 0.62549, a:1.0]

UIColor(r: 255, g: 128, b: 64, a: 255).cmyk() // (c: 0.0, m: 0.498, y: 0.749, k: 0.0)
UIColor(r: 255, g: 128, b: 64, a: 255).cmykArray() // [0.0, 0.498, 0.749, 0.0]

Utilities

Complementary

Returns complementary color.

let color = UIColor.whiteColor().complementaryColor() 
color.rgba() // (r: 0, g: 0, b: 0, a: 255)

Lighten

Lightens the color a given amount, from 0.0 to 1.0. Providing 1.0 will always return white.

let color = UIColor.redColor().lighten()
color.rgba() // (r: 255, g: 51, b: 51, a: 255)
let color = UIColor.redColor().lighten(1.0)
color.rgba() // (r: 255, g: 255, b: 255, a: 255)

Darken

Darkens the color a given amount, from 0.0 to 1.0. Providing 1.0 will always return black.

let color = UIColor.redColor().darken()
color.rgba() // (r: 204, g: 0, b: 0, a: 255)
let color = UIColor.redColor().darken(1.0)
color.rgba() // (r: 0, g: 0, b: 0, a: 255)

Grayscale

Desaturates a color into greyscale.

let color = UIColor(r: 67, g: 122, b: 134).grayscale()
color.rgba() // (r: 106, g: 106, b: 106, a: 255)

IsLight

Returns true when the color's perceived brightness is light.

UIColor.whiteColor().isLight() // true

UIColor.blackColor().isLight() // false

IsDark

Returns true when the color's perceived brightness is dark.

UIColor.blackColor().isLight() // true

UIColor.whiteColor().isLight() // false

Random

Returns a random color.

let color = UIColor.randomColor()
color.rgba() // (r: 67, g: 122, b: 134 a:255)

License

Felucia is released under the MIT license. See LICENSE for details.

GitHub

link
Stars: 5
Last commit: 4 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

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