cforlando/orlando-walking-tours-ios

View on GitHub
Orlando Walking Tours/Extensions/UIColor+HexColor.swift

Summary

Maintainability
A
0 mins
Test Coverage
//
//  UIColor+HexColor.swift
//  Orlando Walking Tours
//
//  Created by Keli'i Martin on 6/19/16.
//  Copyright © 2016 Code for Orlando. All rights reserved.
//

import UIKit

extension UIColor
{
    convenience init(red: Int, green: Int, blue: Int)
    {
        assert(red >= 0 && red <= 255, "Invalid red component")
        assert(green >= 0 && green <= 255, "Invalid green component")
        assert(blue >= 0 && blue <= 255, "Invalid blue component")

        self.init(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: 1.0)
    }

    ////////////////////////////////////////////////////////////

    convenience init(hex: Int)
    {
        self.init(red: (hex >> 16) & 0xff, green: (hex >> 8) & 0xff, blue: hex & 0xff)
    }
}