Latest 1.1.1
Homepage https://github.com/wltrup/iOS-Swift-WTUIColorExtensions
License MIT
Platforms ios 8.0
Authors

CI Status
Version
License
Platform

What

WTUIColorExtensions adds to UIColor the ability to generate pseudo-random color instances
and methods to extract color components in a more direct way than using inout arguments and
the default get... methods. Here’s the full set of API additions:

    public static var randomRGB: UIColor { get }
    public static var randomRGBA: UIColor { get }

    public static var randomHSB: UIColor { get }
    public static var randomHSBA: UIColor { get }

    public static var randomWhite: UIColor { get }
    public static var randomWhiteAlpha: UIColor { get }

    public enum ColorError : Error {
        case invalidColorSpace
    }

    public struct RGBAComponents {
        public let red: CGFloat
        public let green: CGFloat
        public let blue: CGFloat
        public let alpha: CGFloat
    }
    public func rgbaComponents() throws -> RGBAComponents

    public struct HSBAComponents {
        public let hue: CGFloat
        public let saturation: CGFloat
        public let brightness: CGFloat
        public let alpha: CGFloat
    }
    public func hsbaComponents() throws -> HSBAComponents

    public struct WhiteAlphaComponents {
        public let white: CGFloat
        public let alpha: CGFloat
    }
    public func whiteAlphaComponents() throws -> WhiteAlphaComponents

    // NEW in v. 1.1.0
    public func hexValue() throws -> String
    public func hexValueWithAlpha() throws -> String

    // NEW in v. 1.1.0
    public static func quadraticLuma(red: CGFloat, green: CGFloat, blue: CGFloat) throws -> CGFloat
    public func quadraticLuma() throws -> CGFloat

    // NEW in v. 1.1.0
    public func contrastingColor(continuous: Bool, threshold: CGFloat, sameAlpha: Bool) throws -> UIColor
}

Why

Because generating random colors is a common enough need and because having to use inout
arguments to extract color components is annoying.

Tests

WTUIColorExtensions adds several extensions, all tested by 26 tests with nearly 95% coverage.
The missing 5% test-coverage is due to the fact that rgbaComponents() and hsbaComponents()
don’t actually throw any invalid color space errors on iOS, although in theory they could.
In order to future-proof this library, I’ve assumed that those methods might fail but I can’t
currently test that code path.

Changelog

Changes to WTUIColorExtensions are listed
here.

Installation

WTUIColorExtensions is available through CocoaPods. To install
it, simply add the following line to your Podfile:

pod "WTUIColorExtensions"

Author

Wagner Truppel, [email protected]

License

WTUIColorExtensions is available under the MIT license. See the LICENSE file for more info.

Latest podspec

{
    "name": "WTUIColorExtensions",
    "version": "1.1.1",
    "summary": "WTUIColorExtensions adds methods to generate pseudo-random colors, and more.",
    "description": "WTUIColorExtensions adds methods to generate pseudo-random colors, methods tonextract the color components of a color instance in a more direct way than thendefault API does, methods to obtain the hexadecimal representation of an RGB color,nmethods to obtain the color's luminance, and a method to obtain the most contrastingncolor to a given color.",
    "homepage": "https://github.com/wltrup/iOS-Swift-WTUIColorExtensions",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Wagner Truppel": "[email protected]"
    },
    "source": {
        "git": "https://github.com/wltrup/iOS-Swift-WTUIColorExtensions.git",
        "tag": "1.1.1"
    },
    "platforms": {
        "ios": "8.0"
    },
    "source_files": "WTUIColorExtensions/Classes/**/*",
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This