Merge branch 'develop' of https://gitlab.verizon.com/BPHV_MIPS/mvm_core_ui into feature/list_fourcolumn_datausage_divider
This commit is contained in:
commit
fea104adc8
@ -62,6 +62,14 @@ public final class Color: Codable {
|
|||||||
determineRGBA()
|
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
|
// MARK: - Codable Initializers
|
||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
@ -69,21 +77,10 @@ public final class Color: Codable {
|
|||||||
required public init(from decoder: Decoder) throws {
|
required public init(from decoder: Decoder) throws {
|
||||||
let container = try decoder.singleValueContainer()
|
let container = try decoder.singleValueContainer()
|
||||||
let colorString = try container.decode(String.self)
|
let colorString = try container.decode(String.self)
|
||||||
|
let components = try Color.getColorComponents(for: colorString)
|
||||||
if colorString.hasPrefix("#") {
|
self.uiColor = components.color
|
||||||
hex = colorString.replacingOccurrences(of: "#", with: "")
|
hex = components.hex
|
||||||
} else {
|
name = components.name ?? ""
|
||||||
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)
|
|
||||||
}
|
|
||||||
|
|
||||||
determineRGBA()
|
determineRGBA()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -95,6 +92,25 @@ public final class Color: Codable {
|
|||||||
//--------------------------------------------------
|
//--------------------------------------------------
|
||||||
// MARK: - Methods
|
// 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 {
|
public func convertHexToFloat(start: String.Index, end: String.Index) -> CGFloat {
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user