Hi everyone, I want to create Color class that cov...
# multiplatform
b
Hi everyone, I want to create Color class that cover both Android and iOS like this
Copy code
expect class Color

// androidMain
actual typealias Color = androidx.compose.ui.graphics.Color

// iosMain
actual typealias Color = platform.UIKit.UIColor
but it fail because UIColor and compose Color has different constructor. Can we have a workaround in this case?
o
I use this method to use the same color for both platforms Kotlin code.
Copy code
fun Int.toUIColor(): UIColor {
    return asd(
        red = (this shr 16) and 0xFF,
        green = (this shr 8) and 0xFF,
        blue = this and 0xFF,
        a = (this shr 24) and 0xFF
    )
}
Copy code
const val wrongAnswerColor: Int = 0x61B60202
Copy code
val wrongAnswerColor = ColorObject.wrongAnswerColor.toUIColor()
after this I can use it in Xcode //swift textBackColor: IosColorObject.shared.wrongAnswerColor
348 Views