In Objective-C, we use this code to set RGB color codes for views:
#define UIColorFromRGB(rgbValue)
[UIColor colorWithRed:((float)((rgbValue & 0x
adding a swift 3 option:
cell.layer.borderColor = UIColor (red: 192.0/255.0, green: 192.0/255.0, blue: 197/255.0, alpha: 1.0).cgColor
That can be simply done by using this initialization
view.backgroundColor = UIColor(hex: "067AB5")
I have used the following in swift.
let appRedColor = UIColor(red: 200.0/255.0, green: 16.0/255.0, blue: 46.0/255.0, alpha: 1.0)
let appSilverColor = UIColor(red: 236.0/255.0, green: 236.0/255.0, blue: 236.0/255.0, alpha: 1.0)
let appWhiteColor = UIColor(red: 255.0/255.0, green: 255.0/255.0, blue: 255.0/255.0, alpha: 1.0)
let appNavyColor = UIColor(red: 19.0/255.0, green: 41.0/255.0, blue: 75.0/255.0, alpha: 1.0)
This is a nice extension for UIColor. You can use enum values(hex, string) and direct string values when you creating UIColor objects.
The extension we deserve https://github.com/ioramashvili/UsefulExtensions/blob/master/Extensions.playground/Pages/UIColor.xcplaygroundpage/Contents.swift
solution for argb format:
// UIColorExtensions.swift
import UIKit
extension UIColor {
convenience init(argb: UInt) {
self.init(
red: CGFloat((argb & 0xFF0000) >> 16) / 255.0,
green: CGFloat((argb & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(argb & 0x0000FF) / 255.0,
alpha: CGFloat((argb & 0xFF000000) >> 24) / 255.0
)
}
}
usage:
var clearColor: UIColor = UIColor.init(argb: 0x00000000)
var redColor: UIColor = UIColor.init(argb: 0xFFFF0000)
button.layer.backgroundColor = UIColor(red: 112.0/255, green: 86.0/255, blue: 164.0/255, alpha: 1.0).cgColor