Latest 8.0
Homepage https://github.com/igormatyushkin014/RainbowColors
License MIT
Platforms ios 9.0
Authors

RainbowColors

RainbowColors
RainbowColors
RainbowColors
RainbowColors

The purpose of RainbowColors library is to simplify common tasks with colors in iOS, which makes implementation of colorful UI designs easier. Absolutely compatible with native iOS SDK.

How To Get Started

  • Copy content of RainbowColors folder to your project.

or

  • Use RainbowColors cocoapod

Requirements

  • iOS 9 and later
  • Xcode 9 and later
  • Swift 4

Usage

Color Initialization

The common expression for color in RGB system is #123456. Another variety of this expression looks like #123 which is equivalent to #112233. The same time, iOS SDK doesn’t support those expressions above and requires to use CGFloat values for red, green, blue and alpha component in constructor of UIColor class. Not comfortable enough, right?

RainbowColors has a solution for the problem described above, so instead of this

let grayColor = UIColor(red: 51.0 / 255.0, green: 51.0 / 255.0, blue: 51.0, alpha: 255.0)

you can simply write this

let grayColor = UIColor(hexString: "#333333")

or this

let grayColor = UIColor(hexString: "#333")

or even this

let grayColor = UIColor(hexString: "333")

As you can see in last example, sharp symbol is optional. Hex string will be parsed correctly with or without sharp prefix.

RainbowColors supports both RGB and RGBA color systems, so you can also add alpha component to expression:

let grayColorWithSmallTransparency = UIColor(hexString: "#333333dd") // {51, 51, 51, 221}
let halfTransparentGrayColor = UIColor(hexString: "#3338") // {51, 51, 51, 136}
let almostTransparentGrayColor = UIColor(hexString: "#33333310") // {51, 51, 51, 16}

If hex string has wrong format, nil will be returned instead of color.

Brand Colors

Sometimes you don’t know which colors are good enough for your project. But you don’t need to be a professional designer, because you can reuse popular color schemes used by well-known services. RainbowColors has extendable collection of brand colors. All that you need is to write:

let color = UIColor.Brands.Google.blue

or

let color = UIColor.Brands.Flickr.pink

Of course, you are not limited to make any operations with those colors:

let flickrPinkWithHalfTransparency = UIColor.Brands.Flickr.pink.colorWithAlphaComponent(0.5)

To see full collection of available brands, just type in Xcode UIColor.Brands. and you will see output like this:

Available Brands

Another way to check available brands is to take a look at BrandColorCollection.swift file.

License

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

Latest podspec

{
    "name": "RainbowColors",
    "version": "8.0",
    "summary": "Colorful programming.",
    "description": "This library simplifies work with colors in Swift.",
    "homepage": "https://github.com/igormatyushkin014/RainbowColors",
    "screenshots": "https://github.com/igormatyushkin014/RainbowColors/raw/master/Images/logo-1024-300.png",
    "license": {
        "type": "MIT",
        "file": "LICENSE"
    },
    "authors": {
        "Igor Matyushkin": "[email protected]"
    },
    "social_media_url": "https://twitter.com/imatyushkin1",
    "platforms": {
        "ios": "9.0"
    },
    "source": {
        "git": "https://github.com/igormatyushkin014/RainbowColors.git",
        "tag": "8.0"
    },
    "source_files": [
        "RainbowColors",
        "RainbowColors/**/*"
    ],
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This