Created
September 3, 2023 15:14
-
-
Save Kashif-E/c135390043f6bd7b685406245d6f9d69 to your computer and use it in GitHub Desktop.
Material Color to UIColor
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
val uiColor = MaterialTheme.colors.surface.toUIColor() | |
@OptIn(ExperimentalForeignApi::class) | |
fun Color.toUIColor(): UIColor { | |
val colorSpace = CGColorSpaceCreateDeviceRGB() | |
val components = nativeHeap.allocArray<DoubleVar>(4) | |
components[0] = red.toDouble() | |
components[1] = green.toDouble() | |
components[2] = blue.toDouble() | |
components[3] = alpha.toDouble() | |
val cgColor = CGColorCreate(colorSpace, components) | |
return UIColor.colorWithCGColor(cgColor) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment