Created
May 3, 2021 07:16
-
-
Save Enchan1207/81f70545cdb399501960116267c1cadc to your computer and use it in GitHub Desktop.
CGColorからカラーコードを生成
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension CGColor { | |
// convert to color-code string | |
public var hexCodeRepresentation: String? { | |
get{ | |
guard let components = self.components else {return nil} | |
let colorCode = components.map({$0 * 255.0}) | |
.compactMap({UInt8($0)}) | |
.map({String(format: "%02X", $0)}) | |
.joined() | |
return "#\(colorCode)" | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment