Error[8]: Undefined offset: 4, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

如何在Swift中创建十六进制颜色字符串UIColor初始化程序?[重复]

Xpre 9•Swift 4或更高版本

extension UIColor {    convenience init?(hexaRGB: String, alpha: CGFloat = 1) {        var chars = Array(hexaRGB.hasPrefix("#") ? hexaRGB.dropFirst() : hexaRGB[...])        switch chars.count {        case 3: chars = chars.flatMap { [
if let textColor = UIColor(hexa: "00F") {    print(textColor) // r 0.0 g 0.0 b 1.0 a 1.0}
,
if let textColor = UIColor(hexaRGB: "00F") {    print(textColor) // r 0.0 g 0.0 b 1.0 a 1.0}UIColor(hexaRGB: "#00F")       // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaRGB: "#00F", alpha: 0.5)      // r 0.0 g 0.0 b 1.0 a 0.5UIColor(hexaRGB: "#0000FF")    // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaRGB: "#0000FF", alpha: 0.5)   // r 0.0 g 0.0 b 1.0 a 0.5UIColor(hexaRGBA: "#0000FFFF") // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaRGBA: "#0000FF7F") // r 0.0 g 0.0 b 1.0 a 0.498UIColor(hexaARGB: "#FF0000FF") // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaARGB: "#7F0000FF") // r 0.0 g 0.0 b 1.0 a 0.498
] } case 6: break default: return nil } self.init(red: .init(strtoul(String(chars[0...1]), nil, 16)) / 255, green: .init(strtoul(String(chars[2...3]), nil, 16)) / 255, blue: .init(strtoul(String(chars[4...5]), nil, 16)) / 255, alpha: alpha) } convenience init?(hexaRGBA: String) { var chars = Array(hexaRGBA.hasPrefix("#") ? hexaRGBA.dropFirst() : hexaRGBA[...]) switch chars.count { case 3: chars = chars.flatMap { [[+++], [+++]] }; fallthrough case 6: chars.append(contentsOf: ["F","F"]) case 8: break default: return nil } self.init(red: .init(strtoul(String(chars[0...1]), nil, 16)) / 255, green: .init(strtoul(String(chars[2...3]), nil, 16)) / 255, blue: .init(strtoul(String(chars[4...5]), nil, 16)) / 255, alpha: .init(strtoul(String(chars[6...7]), nil, 16)) / 255) } convenience init?(hexaARGB: String) { var chars = Array(hexaARGB.hasPrefix("#") ? hexaARGB.dropFirst() : hexaARGB[...]) switch chars.count { case 3: chars = chars.flatMap { [[+++], [+++]] }; fallthrough case 6: chars.append(contentsOf: ["F","F"]) case 8: break default: return nil } self.init(red: .init(strtoul(String(chars[2...3]), nil, 16)) / 255, green: .init(strtoul(String(chars[4...5]), nil, 16)) / 255, blue: .init(strtoul(String(chars[6...7]), nil, 16)) / 255, alpha: .init(strtoul(String(chars[0...1]), nil, 16)) / 255) }}

[+++]

[+++]



)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 5, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

如何在Swift中创建十六进制颜色字符串UIColor初始化程序?[重复]

Xpre 9•Swift 4或更高版本

extension UIColor {    convenience init?(hexaRGB: String, alpha: CGFloat = 1) {        var chars = Array(hexaRGB.hasPrefix("#") ? hexaRGB.dropFirst() : hexaRGB[...])        switch chars.count {        case 3: chars = chars.flatMap { [
if let textColor = UIColor(hexa: "00F") {    print(textColor) // r 0.0 g 0.0 b 1.0 a 1.0}
,
if let textColor = UIColor(hexaRGB: "00F") {    print(textColor) // r 0.0 g 0.0 b 1.0 a 1.0}UIColor(hexaRGB: "#00F")       // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaRGB: "#00F", alpha: 0.5)      // r 0.0 g 0.0 b 1.0 a 0.5UIColor(hexaRGB: "#0000FF")    // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaRGB: "#0000FF", alpha: 0.5)   // r 0.0 g 0.0 b 1.0 a 0.5UIColor(hexaRGBA: "#0000FFFF") // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaRGBA: "#0000FF7F") // r 0.0 g 0.0 b 1.0 a 0.498UIColor(hexaARGB: "#FF0000FF") // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaARGB: "#7F0000FF") // r 0.0 g 0.0 b 1.0 a 0.498
] } case 6: break default: return nil } self.init(red: .init(strtoul(String(chars[0...1]), nil, 16)) / 255, green: .init(strtoul(String(chars[2...3]), nil, 16)) / 255, blue: .init(strtoul(String(chars[4...5]), nil, 16)) / 255, alpha: alpha) } convenience init?(hexaRGBA: String) { var chars = Array(hexaRGBA.hasPrefix("#") ? hexaRGBA.dropFirst() : hexaRGBA[...]) switch chars.count { case 3: chars = chars.flatMap { [, [+++]] }; fallthrough case 6: chars.append(contentsOf: ["F","F"]) case 8: break default: return nil } self.init(red: .init(strtoul(String(chars[0...1]), nil, 16)) / 255, green: .init(strtoul(String(chars[2...3]), nil, 16)) / 255, blue: .init(strtoul(String(chars[4...5]), nil, 16)) / 255, alpha: .init(strtoul(String(chars[6...7]), nil, 16)) / 255) } convenience init?(hexaARGB: String) { var chars = Array(hexaARGB.hasPrefix("#") ? hexaARGB.dropFirst() : hexaARGB[...]) switch chars.count { case 3: chars = chars.flatMap { [[+++], [+++]] }; fallthrough case 6: chars.append(contentsOf: ["F","F"]) case 8: break default: return nil } self.init(red: .init(strtoul(String(chars[2...3]), nil, 16)) / 255, green: .init(strtoul(String(chars[4...5]), nil, 16)) / 255, blue: .init(strtoul(String(chars[6...7]), nil, 16)) / 255, alpha: .init(strtoul(String(chars[0...1]), nil, 16)) / 255) }}

[+++]

[+++]



)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 6, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

如何在Swift中创建十六进制颜色字符串UIColor初始化程序?[重复]

Xpre 9•Swift 4或更高版本

extension UIColor {    convenience init?(hexaRGB: String, alpha: CGFloat = 1) {        var chars = Array(hexaRGB.hasPrefix("#") ? hexaRGB.dropFirst() : hexaRGB[...])        switch chars.count {        case 3: chars = chars.flatMap { [
if let textColor = UIColor(hexa: "00F") {    print(textColor) // r 0.0 g 0.0 b 1.0 a 1.0}
,
if let textColor = UIColor(hexaRGB: "00F") {    print(textColor) // r 0.0 g 0.0 b 1.0 a 1.0}UIColor(hexaRGB: "#00F")       // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaRGB: "#00F", alpha: 0.5)      // r 0.0 g 0.0 b 1.0 a 0.5UIColor(hexaRGB: "#0000FF")    // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaRGB: "#0000FF", alpha: 0.5)   // r 0.0 g 0.0 b 1.0 a 0.5UIColor(hexaRGBA: "#0000FFFF") // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaRGBA: "#0000FF7F") // r 0.0 g 0.0 b 1.0 a 0.498UIColor(hexaARGB: "#FF0000FF") // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaARGB: "#7F0000FF") // r 0.0 g 0.0 b 1.0 a 0.498
] } case 6: break default: return nil } self.init(red: .init(strtoul(String(chars[0...1]), nil, 16)) / 255, green: .init(strtoul(String(chars[2...3]), nil, 16)) / 255, blue: .init(strtoul(String(chars[4...5]), nil, 16)) / 255, alpha: alpha) } convenience init?(hexaRGBA: String) { var chars = Array(hexaRGBA.hasPrefix("#") ? hexaRGBA.dropFirst() : hexaRGBA[...]) switch chars.count { case 3: chars = chars.flatMap { [, ] }; fallthrough case 6: chars.append(contentsOf: ["F","F"]) case 8: break default: return nil } self.init(red: .init(strtoul(String(chars[0...1]), nil, 16)) / 255, green: .init(strtoul(String(chars[2...3]), nil, 16)) / 255, blue: .init(strtoul(String(chars[4...5]), nil, 16)) / 255, alpha: .init(strtoul(String(chars[6...7]), nil, 16)) / 255) } convenience init?(hexaARGB: String) { var chars = Array(hexaARGB.hasPrefix("#") ? hexaARGB.dropFirst() : hexaARGB[...]) switch chars.count { case 3: chars = chars.flatMap { [[+++], [+++]] }; fallthrough case 6: chars.append(contentsOf: ["F","F"]) case 8: break default: return nil } self.init(red: .init(strtoul(String(chars[2...3]), nil, 16)) / 255, green: .init(strtoul(String(chars[4...5]), nil, 16)) / 255, blue: .init(strtoul(String(chars[6...7]), nil, 16)) / 255, alpha: .init(strtoul(String(chars[0...1]), nil, 16)) / 255) }}

[+++]

[+++]



)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 7, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

如何在Swift中创建十六进制颜色字符串UIColor初始化程序?[重复]

Xpre 9•Swift 4或更高版本

extension UIColor {    convenience init?(hexaRGB: String, alpha: CGFloat = 1) {        var chars = Array(hexaRGB.hasPrefix("#") ? hexaRGB.dropFirst() : hexaRGB[...])        switch chars.count {        case 3: chars = chars.flatMap { [
if let textColor = UIColor(hexa: "00F") {    print(textColor) // r 0.0 g 0.0 b 1.0 a 1.0}
,
if let textColor = UIColor(hexaRGB: "00F") {    print(textColor) // r 0.0 g 0.0 b 1.0 a 1.0}UIColor(hexaRGB: "#00F")       // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaRGB: "#00F", alpha: 0.5)      // r 0.0 g 0.0 b 1.0 a 0.5UIColor(hexaRGB: "#0000FF")    // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaRGB: "#0000FF", alpha: 0.5)   // r 0.0 g 0.0 b 1.0 a 0.5UIColor(hexaRGBA: "#0000FFFF") // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaRGBA: "#0000FF7F") // r 0.0 g 0.0 b 1.0 a 0.498UIColor(hexaARGB: "#FF0000FF") // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaARGB: "#7F0000FF") // r 0.0 g 0.0 b 1.0 a 0.498
] } case 6: break default: return nil } self.init(red: .init(strtoul(String(chars[0...1]), nil, 16)) / 255, green: .init(strtoul(String(chars[2...3]), nil, 16)) / 255, blue: .init(strtoul(String(chars[4...5]), nil, 16)) / 255, alpha: alpha) } convenience init?(hexaRGBA: String) { var chars = Array(hexaRGBA.hasPrefix("#") ? hexaRGBA.dropFirst() : hexaRGBA[...]) switch chars.count { case 3: chars = chars.flatMap { [, ] }; fallthrough case 6: chars.append(contentsOf: ["F","F"]) case 8: break default: return nil } self.init(red: .init(strtoul(String(chars[0...1]), nil, 16)) / 255, green: .init(strtoul(String(chars[2...3]), nil, 16)) / 255, blue: .init(strtoul(String(chars[4...5]), nil, 16)) / 255, alpha: .init(strtoul(String(chars[6...7]), nil, 16)) / 255) } convenience init?(hexaARGB: String) { var chars = Array(hexaARGB.hasPrefix("#") ? hexaARGB.dropFirst() : hexaARGB[...]) switch chars.count { case 3: chars = chars.flatMap { [, [+++]] }; fallthrough case 6: chars.append(contentsOf: ["F","F"]) case 8: break default: return nil } self.init(red: .init(strtoul(String(chars[2...3]), nil, 16)) / 255, green: .init(strtoul(String(chars[4...5]), nil, 16)) / 255, blue: .init(strtoul(String(chars[6...7]), nil, 16)) / 255, alpha: .init(strtoul(String(chars[0...1]), nil, 16)) / 255) }}

[+++]

[+++]



)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 8, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

如何在Swift中创建十六进制颜色字符串UIColor初始化程序?[重复]

Xpre 9•Swift 4或更高版本

extension UIColor {    convenience init?(hexaRGB: String, alpha: CGFloat = 1) {        var chars = Array(hexaRGB.hasPrefix("#") ? hexaRGB.dropFirst() : hexaRGB[...])        switch chars.count {        case 3: chars = chars.flatMap { [
if let textColor = UIColor(hexa: "00F") {    print(textColor) // r 0.0 g 0.0 b 1.0 a 1.0}
,
if let textColor = UIColor(hexaRGB: "00F") {    print(textColor) // r 0.0 g 0.0 b 1.0 a 1.0}UIColor(hexaRGB: "#00F")       // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaRGB: "#00F", alpha: 0.5)      // r 0.0 g 0.0 b 1.0 a 0.5UIColor(hexaRGB: "#0000FF")    // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaRGB: "#0000FF", alpha: 0.5)   // r 0.0 g 0.0 b 1.0 a 0.5UIColor(hexaRGBA: "#0000FFFF") // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaRGBA: "#0000FF7F") // r 0.0 g 0.0 b 1.0 a 0.498UIColor(hexaARGB: "#FF0000FF") // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaARGB: "#7F0000FF") // r 0.0 g 0.0 b 1.0 a 0.498
] } case 6: break default: return nil } self.init(red: .init(strtoul(String(chars[0...1]), nil, 16)) / 255, green: .init(strtoul(String(chars[2...3]), nil, 16)) / 255, blue: .init(strtoul(String(chars[4...5]), nil, 16)) / 255, alpha: alpha) } convenience init?(hexaRGBA: String) { var chars = Array(hexaRGBA.hasPrefix("#") ? hexaRGBA.dropFirst() : hexaRGBA[...]) switch chars.count { case 3: chars = chars.flatMap { [, ] }; fallthrough case 6: chars.append(contentsOf: ["F","F"]) case 8: break default: return nil } self.init(red: .init(strtoul(String(chars[0...1]), nil, 16)) / 255, green: .init(strtoul(String(chars[2...3]), nil, 16)) / 255, blue: .init(strtoul(String(chars[4...5]), nil, 16)) / 255, alpha: .init(strtoul(String(chars[6...7]), nil, 16)) / 255) } convenience init?(hexaARGB: String) { var chars = Array(hexaARGB.hasPrefix("#") ? hexaARGB.dropFirst() : hexaARGB[...]) switch chars.count { case 3: chars = chars.flatMap { [, ] }; fallthrough case 6: chars.append(contentsOf: ["F","F"]) case 8: break default: return nil } self.init(red: .init(strtoul(String(chars[2...3]), nil, 16)) / 255, green: .init(strtoul(String(chars[4...5]), nil, 16)) / 255, blue: .init(strtoul(String(chars[6...7]), nil, 16)) / 255, alpha: .init(strtoul(String(chars[0...1]), nil, 16)) / 255) }}

[+++]

[+++]



)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 9, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

如何在Swift中创建十六进制颜色字符串UIColor初始化程序?[重复]

Xpre 9•Swift 4或更高版本

extension UIColor {    convenience init?(hexaRGB: String, alpha: CGFloat = 1) {        var chars = Array(hexaRGB.hasPrefix("#") ? hexaRGB.dropFirst() : hexaRGB[...])        switch chars.count {        case 3: chars = chars.flatMap { [
if let textColor = UIColor(hexa: "00F") {    print(textColor) // r 0.0 g 0.0 b 1.0 a 1.0}
,
if let textColor = UIColor(hexaRGB: "00F") {    print(textColor) // r 0.0 g 0.0 b 1.0 a 1.0}UIColor(hexaRGB: "#00F")       // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaRGB: "#00F", alpha: 0.5)      // r 0.0 g 0.0 b 1.0 a 0.5UIColor(hexaRGB: "#0000FF")    // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaRGB: "#0000FF", alpha: 0.5)   // r 0.0 g 0.0 b 1.0 a 0.5UIColor(hexaRGBA: "#0000FFFF") // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaRGBA: "#0000FF7F") // r 0.0 g 0.0 b 1.0 a 0.498UIColor(hexaARGB: "#FF0000FF") // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaARGB: "#7F0000FF") // r 0.0 g 0.0 b 1.0 a 0.498
] } case 6: break default: return nil } self.init(red: .init(strtoul(String(chars[0...1]), nil, 16)) / 255, green: .init(strtoul(String(chars[2...3]), nil, 16)) / 255, blue: .init(strtoul(String(chars[4...5]), nil, 16)) / 255, alpha: alpha) } convenience init?(hexaRGBA: String) { var chars = Array(hexaRGBA.hasPrefix("#") ? hexaRGBA.dropFirst() : hexaRGBA[...]) switch chars.count { case 3: chars = chars.flatMap { [, ] }; fallthrough case 6: chars.append(contentsOf: ["F","F"]) case 8: break default: return nil } self.init(red: .init(strtoul(String(chars[0...1]), nil, 16)) / 255, green: .init(strtoul(String(chars[2...3]), nil, 16)) / 255, blue: .init(strtoul(String(chars[4...5]), nil, 16)) / 255, alpha: .init(strtoul(String(chars[6...7]), nil, 16)) / 255) } convenience init?(hexaARGB: String) { var chars = Array(hexaARGB.hasPrefix("#") ? hexaARGB.dropFirst() : hexaARGB[...]) switch chars.count { case 3: chars = chars.flatMap { [, ] }; fallthrough case 6: chars.append(contentsOf: ["F","F"]) case 8: break default: return nil } self.init(red: .init(strtoul(String(chars[2...3]), nil, 16)) / 255, green: .init(strtoul(String(chars[4...5]), nil, 16)) / 255, blue: .init(strtoul(String(chars[6...7]), nil, 16)) / 255, alpha: .init(strtoul(String(chars[0...1]), nil, 16)) / 255) }}


[+++]



)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 165, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
如何在Swift中创建十六进制颜色字符串UIColor初始化程序?[重复]_随笔_内存溢出

如何在Swift中创建十六进制颜色字符串UIColor初始化程序?[重复]

如何在Swift中创建十六进制颜色字符串UIColor初始化程序?[重复],第1张

如何在Swift中创建十六进制颜色字符串UIColor初始化程序?[重复]

Xpre 9•Swift 4或更高版本

extension UIColor {    convenience init?(hexaRGB: String, alpha: CGFloat = 1) {        var chars = Array(hexaRGB.hasPrefix("#") ? hexaRGB.dropFirst() : hexaRGB[...])        switch chars.count {        case 3: chars = chars.flatMap { [
if let textColor = UIColor(hexa: "00F") {    print(textColor) // r 0.0 g 0.0 b 1.0 a 1.0}
,
if let textColor = UIColor(hexaRGB: "00F") {    print(textColor) // r 0.0 g 0.0 b 1.0 a 1.0}UIColor(hexaRGB: "#00F")       // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaRGB: "#00F", alpha: 0.5)      // r 0.0 g 0.0 b 1.0 a 0.5UIColor(hexaRGB: "#0000FF")    // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaRGB: "#0000FF", alpha: 0.5)   // r 0.0 g 0.0 b 1.0 a 0.5UIColor(hexaRGBA: "#0000FFFF") // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaRGBA: "#0000FF7F") // r 0.0 g 0.0 b 1.0 a 0.498UIColor(hexaARGB: "#FF0000FF") // r 0.0 g 0.0 b 1.0 a 1.0UIColor(hexaARGB: "#7F0000FF") // r 0.0 g 0.0 b 1.0 a 0.498
] } case 6: break default: return nil } self.init(red: .init(strtoul(String(chars[0...1]), nil, 16)) / 255, green: .init(strtoul(String(chars[2...3]), nil, 16)) / 255, blue: .init(strtoul(String(chars[4...5]), nil, 16)) / 255, alpha: alpha) } convenience init?(hexaRGBA: String) { var chars = Array(hexaRGBA.hasPrefix("#") ? hexaRGBA.dropFirst() : hexaRGBA[...]) switch chars.count { case 3: chars = chars.flatMap { [, ] }; fallthrough case 6: chars.append(contentsOf: ["F","F"]) case 8: break default: return nil } self.init(red: .init(strtoul(String(chars[0...1]), nil, 16)) / 255, green: .init(strtoul(String(chars[2...3]), nil, 16)) / 255, blue: .init(strtoul(String(chars[4...5]), nil, 16)) / 255, alpha: .init(strtoul(String(chars[6...7]), nil, 16)) / 255) } convenience init?(hexaARGB: String) { var chars = Array(hexaARGB.hasPrefix("#") ? hexaARGB.dropFirst() : hexaARGB[...]) switch chars.count { case 3: chars = chars.flatMap { [, ] }; fallthrough case 6: chars.append(contentsOf: ["F","F"]) case 8: break default: return nil } self.init(red: .init(strtoul(String(chars[2...3]), nil, 16)) / 255, green: .init(strtoul(String(chars[4...5]), nil, 16)) / 255, blue: .init(strtoul(String(chars[6...7]), nil, 16)) / 255, alpha: .init(strtoul(String(chars[0...1]), nil, 16)) / 255) }}





欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5622481.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-16

发表评论

登录后才能评论

评论列表(0条)

保存