diff --git a/VDS/Extensions/UIColor.swift b/VDS/Extensions/UIColor.swift index 84100106..fa90f2cc 100644 --- a/VDS/Extensions/UIColor.swift +++ b/VDS/Extensions/UIColor.swift @@ -14,26 +14,45 @@ extension UIColor { // MARK: - Functions //-------------------------------------------------- - /// Convenience to get a grayscale UIColor where the same value is used for red, green, and blue. + /// Convenience to get a grayscale UIColor where the same value is used for red, green, and blue + /// - Parameters: + /// - rgb: red, green, and blue + /// - alpha: alphay + /// - Returns: UIColor that will be grayscale public class func grayscale(rgb: Int, alpha: CGFloat = 1.0) -> UIColor { let grayscale = CGFloat(rgb) / 255.0 return UIColor(red: grayscale, green: grayscale, blue: grayscale, alpha: alpha) } - /// Convenience to get a UIColor. + /// Convenience to get an 8-Bit UIColor based on RGB values + /// - Parameters: + /// - red: Value for Red + /// - green: Value for Green + /// - blue: Value for Blue + /// - alpha: Value for Alpha + /// - Returns: UIColor for the values above public class func color8Bits(red: Int, green: Int, blue: Int, alpha: CGFloat = 1.0) -> UIColor { return UIColor(red: CGFloat(red) / 255.0, green: CGFloat(green) / 255.0, blue: CGFloat(blue) / 255.0, alpha: alpha) } - /// Convenience to get a UIColor. + /// Convenience to get an UIColor based on RGB values + /// - Parameters: + /// - red: Value for Red + /// - green: Value for Green + /// - blue: Value for Blue + /// - alpha: Value for Alpha + /// - Returns: UIColor for the values above public class func color8Bits(red: CGFloat, green: CGFloat, blue: CGFloat, alpha: CGFloat = 1.0) -> UIColor { return UIColor(red: red / 255.0, green: green / 255.0, blue: blue / 255.0, alpha: alpha) } /// Gets UIColor via an 8 digit hex string. + /// - Parameters: + /// - hex: HexCode string + /// - Returns: UIColor for the values above public class func getColorBy(hex: String) -> UIColor { var hexint: UInt64 = 0 @@ -48,7 +67,10 @@ extension UIColor { alpha: 1) } - /// Gets UIColor via an 8 digit hex string. The last two being the alpha channel. + /// Gets UIColor via an 8 digit hex string that includes transparency. + /// - Parameters: + /// - hex: HexCode string + /// - Returns: UIColor for the values above public class func getColorWithTransparencyBy(hex: String) -> UIColor { var hexint: UInt64 = 0 @@ -63,6 +85,9 @@ extension UIColor { alpha: (CGFloat(hexint & 0xFF)) / 255) } + /// Generates a gradient color for the color passed in + /// - Parameter color: Primary color for the gradient + /// - Returns: UIColor that is gradient public class func gradientColor(_ color: UIColor?) -> UIColor { var h: CGFloat = 0 @@ -77,7 +102,9 @@ extension UIColor { return .white } - /// - parameter color: The UIColor intended to retrieve its hex value. + /// Gets the hex code value for a UIColor + /// - Parameter color: UIColor intended to retrieve its hex value + /// - Returns: Hex Code public class func hexString(for color: UIColor) -> String? { guard let components = color.cgColor.components else { return nil } @@ -111,7 +138,8 @@ extension UIColor { return nil } - /// - parameter color: The UIColor intended to retrieve its hex value. + /// Gets the hex code value for the current UIColor + /// - Returns: Hex Code string public var hexString: String? { guard let components = cgColor.components else { return nil } @@ -145,6 +173,8 @@ extension UIColor { return nil } + /// Initialize a UIColor with a HexCode string + /// - Parameter hexString: HexCode string to convert to a UIColor public convenience init(hexString: String) { let hex = hexString.trimmingCharacters(in: CharacterSet.alphanumerics.inverted) var int = UInt64() @@ -163,23 +193,3 @@ extension UIColor { self.init(red: CGFloat(r) / 255, green: CGFloat(g) / 255, blue: CGFloat(b) / 255, alpha: CGFloat(a) / 255) } } - -extension UIColor { - convenience init( - light lightModeColor: @escaping @autoclosure () -> UIColor, - dark darkModeColor: @escaping @autoclosure () -> UIColor - ) { - self.init { traitCollection in - switch traitCollection.userInterfaceStyle { - case .light: - return lightModeColor() - case .dark: - return darkModeColor() - case .unspecified: - return lightModeColor() - @unknown default: - return lightModeColor() - } - } - } -}