From 4b49abdd8a1630173e991c9582f07320167a1889 Mon Sep 17 00:00:00 2001 From: Felix Horvat Date: Wed, 3 Mar 2021 19:55:56 +0100 Subject: [PATCH 1/3] added support for colors with alpha --- ios/Classes/Extensions.swift | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/ios/Classes/Extensions.swift b/ios/Classes/Extensions.swift index 553800391..91febaacd 100644 --- a/ios/Classes/Extensions.swift +++ b/ios/Classes/Extensions.swift @@ -96,16 +96,27 @@ extension UIColor { let start = hexString.index(hexString.startIndex, offsetBy: 1) let hexColor = hexString[start...] + let scanner = Scanner(string: String(hexColor)) + var hexNumber: UInt64 = 0 + if hexColor.count == 6 { - let scanner = Scanner(string: String(hexColor)) - var hexNumber: UInt64 = 0 - if scanner.scanHexInt64(&hexNumber) { r = CGFloat((hexNumber & 0xff0000) >> 16) / 255 g = CGFloat((hexNumber & 0x00ff00) >> 8) / 255 b = CGFloat(hexNumber & 0x0000ff) / 255 a = 255 + self.init(red: r, green: g, blue: b, alpha: a) + return + } + } + else if hexColor.count == 8 { + if scanner.scanHexInt64(&hexNumber) { + r = CGFloat((hexNumber & 0xff000000) >> 24) / 255 + g = CGFloat((hexNumber & 0x00ff0000) >> 16) / 255 + b = CGFloat(hexNumber & 0x0000ff00 >> 8) / 255 + a = CGFloat(hexNumber & 0x000000ff) / 255 + self.init(red: r, green: g, blue: b, alpha: a) return } From b8deebc9ecee8e8a6390e6d3e0bfcbaa06007fae Mon Sep 17 00:00:00 2001 From: Felix Horvat Date: Wed, 3 Mar 2021 20:28:29 +0100 Subject: [PATCH 2/3] fixed brace issue --- ios/Classes/Extensions.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/Classes/Extensions.swift b/ios/Classes/Extensions.swift index 91febaacd..30bd94773 100644 --- a/ios/Classes/Extensions.swift +++ b/ios/Classes/Extensions.swift @@ -114,7 +114,7 @@ extension UIColor { if scanner.scanHexInt64(&hexNumber) { r = CGFloat((hexNumber & 0xff000000) >> 24) / 255 g = CGFloat((hexNumber & 0x00ff0000) >> 16) / 255 - b = CGFloat(hexNumber & 0x0000ff00 >> 8) / 255 + b = CGFloat((hexNumber & 0x0000ff00) >> 8) / 255 a = CGFloat(hexNumber & 0x000000ff) / 255 self.init(red: r, green: g, blue: b, alpha: a) From ab062fa685bf5afb3bf657aeeec88f0555db8135 Mon Sep 17 00:00:00 2001 From: Felix Horvat Date: Wed, 3 Mar 2021 20:31:30 +0100 Subject: [PATCH 3/3] changed squence to argb to match android --- ios/Classes/Extensions.swift | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/ios/Classes/Extensions.swift b/ios/Classes/Extensions.swift index 30bd94773..f433d3ba6 100644 --- a/ios/Classes/Extensions.swift +++ b/ios/Classes/Extensions.swift @@ -112,10 +112,10 @@ extension UIColor { } else if hexColor.count == 8 { if scanner.scanHexInt64(&hexNumber) { - r = CGFloat((hexNumber & 0xff000000) >> 24) / 255 - g = CGFloat((hexNumber & 0x00ff0000) >> 16) / 255 - b = CGFloat((hexNumber & 0x0000ff00) >> 8) / 255 - a = CGFloat(hexNumber & 0x000000ff) / 255 + a = CGFloat((hexNumber & 0xff000000) >> 24) / 255 + r = CGFloat((hexNumber & 0x00ff0000) >> 16) / 255 + g = CGFloat((hexNumber & 0x0000ff00) >> 8) / 255 + b = CGFloat(hexNumber & 0x000000ff) / 255 self.init(red: r, green: g, blue: b, alpha: a) return