forked from gardencoder-zz/react-native-paytabs-library
-
Notifications
You must be signed in to change notification settings - Fork 15
/
UIColor.swift
31 lines (26 loc) · 840 Bytes
/
UIColor.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
//
// UIColor.swift
// react-native-paymentsdk
//
// Created by Muhammad Alkady on 22/12/2022.
//
import Foundation
import UIKit
extension UIColor {
convenience init(hex:String, alpha:CGFloat = 1.0) {
var cString:String = hex.trimmingCharacters(in: .whitespacesAndNewlines).uppercased()
var rgbValue:UInt32 = 10066329 //color #999999 if string has wrong format
if (cString.hasPrefix("#")) {
cString.remove(at: cString.startIndex)
}
if ((cString.count) == 6) {
Scanner(string: cString).scanHexInt32(&rgbValue)
}
self.init(
red: CGFloat((rgbValue & 0xFF0000) >> 16) / 255.0,
green: CGFloat((rgbValue & 0x00FF00) >> 8) / 255.0,
blue: CGFloat(rgbValue & 0x0000FF) / 255.0,
alpha: alpha
)
}
}