Merge branch 'develop' of https://gitlab.verizon.com/BPHV_MIPS/mvm_core_ui into feature/list_fourcolumn_datausage_divider

This commit is contained in:
Pfeil, Scott Robert 2020-02-28 12:12:09 -05:00
commit fea104adc8

View File

@ -62,6 +62,14 @@ public final class Color: Codable {
determineRGBA()
}
public init?(colorString: String) throws {
let components = try Color.getColorComponents(for: colorString)
self.uiColor = components.color
hex = components.hex
name = components.name ?? ""
determineRGBA()
}
//--------------------------------------------------
// MARK: - Codable Initializers
//--------------------------------------------------
@ -69,21 +77,10 @@ public final class Color: Codable {
required public init(from decoder: Decoder) throws {
let container = try decoder.singleValueContainer()
let colorString = try container.decode(String.self)
if colorString.hasPrefix("#") {
hex = colorString.replacingOccurrences(of: "#", with: "")
} else {
guard let hex = UIColor.names[colorString]?.hex else { throw ColorError.badName(reason: "Check the spelling of your color.") }
self.hex = hex.replacingOccurrences(of: "#", with: "")
name = colorString
}
if hex.count == 8 {
uiColor = UIColor.getColorWithTransparencyBy(hex: hex)
} else {
uiColor = UIColor.getColorBy(hex: hex)
}
let components = try Color.getColorComponents(for: colorString)
self.uiColor = components.color
hex = components.hex
name = components.name ?? ""
determineRGBA()
}
@ -95,6 +92,25 @@ public final class Color: Codable {
//--------------------------------------------------
// MARK: - Methods
//--------------------------------------------------
private static func getColorComponents(for colorString: String) throws -> (color: UIColor, hex: String, name: String?) {
var color: UIColor
var hex: String
var name: String?
if colorString.hasPrefix("#") {
hex = colorString.replacingOccurrences(of: "#", with: "")
} else {
guard let hexString = UIColor.names[colorString]?.hex else { throw ColorError.badName(reason: "Check the spelling of your color.") }
hex = hexString.replacingOccurrences(of: "#", with: "")
name = colorString
}
if hex.count == 8 {
color = UIColor.getColorWithTransparencyBy(hex: hex)
} else {
color = UIColor.getColorBy(hex: hex)
}
return (color, hex, name)
}
public func convertHexToFloat(start: String.Index, end: String.Index) -> CGFloat {