TestsTested | ✗ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Oct 2017 |
SwiftSwift Version | 3.0 |
SPMSupports SPM | ✗ |
Maintained by Igor Matyushkin.
RainbowColors
simplifies common tasks with colors in iOS, which makes easier implementation of colorful UI designs. Absolutely compatible with native iOS SDK.
RainbowColors
folder to your project.or
RainbowColors
cocoapodNote: For Swift 2.x use RainbowColors v1.2
. For Swift 3.0 use RainbowColors v3.0
.
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.
Sometimes you don’t know which colors are good enough for your project. Then you can try color schemes of well-known services just to bring some color to app. 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:
Another way to check available brands is to take a look at BrandColorCollection.swift
file.
If you want to add more brand colors to this library, send a pull request. This kind of changes is highly appreciated. Let’s make the largest open-source collection of brand colors for developers :)
RainbowColors
is available under the MIT license. See the LICENSE file for more info.