Skip to content

Instantly share code, notes, and snippets.

@jershell
Last active October 14, 2023 15:23
Show Gist options
  • Save jershell/630dc24fd7e557b3fec092375f12e97e to your computer and use it in GitHub Desktop.
Save jershell/630dc24fd7e557b3fec092375f12e97e to your computer and use it in GitHub Desktop.
compose Color to UIColor
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import platform.UIKit.UIColor
fun Color.toUIColor(): UIColor {
val argb = this.toArgb()
val blue = argb and 0xff;
val green = argb shr 8 and 0xff;
val red = argb shr 16 and 0xff;
val alpha = argb shr 24 and 0xff;
return UIColor(
red = red /255.0,
green = green / 255.0,
blue = blue / 255.0,
alpha = alpha / 255.0
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment