Apple Developer Documentation

How to convert CGColor to UIColor?

let uiColor = UIColor(cgColor: cgColor)

Color Literal

let colorLiteral = colormodal input hex and drag
// 복사해보면 rgb + alpha값이 float 타입으로 들어가 있음

UIColor to hex

How to convert UIColor to HEX and display in NSLog

From Hex to UIColor and Back in Swift

어떻게 뷰의 특정 위치의 color값을 가져올 수 있을까?

https://gist.github.com/mbanasiewicz/940677042f5f293caf57

두 색 사이에서 비율에 따라 중간 색가져오기

<aside> 💡 xcode get color between gradient

</aside>

https://stackoverflow.com/questions/15032562/ios-find-color-at-point-between-two-colors

extension UIColor {
    func toColor(_ color: UIColor, percentage: CGFloat) -> UIColor {
        let percentage = max(min(percentage, 100), 0) / 100
        switch percentage {
        case 0: return self
        case 1: return color
        default:
            var (r1, g1, b1, a1): (CGFloat, CGFloat, CGFloat, CGFloat) = (0, 0, 0, 0)
            var (r2, g2, b2, a2): (CGFloat, CGFloat, CGFloat, CGFloat) = (0, 0, 0, 0)
            guard self.getRed(&r1, green: &g1, blue: &b1, alpha: &a1) else { return self }
            guard color.getRed(&r2, green: &g2, blue: &b2, alpha: &a2) else { return self }

            return UIColor(red: CGFloat(r1 + (r2 - r1) * percentage),
                           green: CGFloat(g1 + (g2 - g1) * percentage),
                           blue: CGFloat(b1 + (b2 - b1) * percentage),
                           alpha: CGFloat(a1 + (a2 - a1) * percentage))
        }
    }
}

//Usage
let colorRed = UIColor.red
let colorBlue = UIColor.blue

let colorOutput = colorRed.toColor(colorBlue, percentage: 50)