Hello! :wave: How would you display images as UIIm...
# compose-ios
v
Hello! 👋 How would you display images as UIImage in iosMain using composeResources library? I’ve tried using this, but with no luck, I always get image null
val image = UIImage.imageNamed("image_name")
in my build.gradle
Copy code
compose.resources {
     customDirectory(
         sourceSetName = "iosMain",
         directoryProvider = provider { layout.projectDirectory.dir("composeResources") }
     )
 }
(Obviously I've created composeResources folder with the same structure as composeApp) But I guess it's only for having custom resources in compose? But what about if I want to display UIimage from my iosMain code?
s
I don't think you'll be able to address the resources directly from the iOS part. Top of my head I would likely read out the imageresource into a byte array, convert the
KotlinByteArray
to
NSData
and then visualize this with a
UIImage
.
🙏 1
f
UIImage.imageNamed("image_name")
is loading only asset stored inside the xcasset folder.
v
Tried to store the .png file there as well, but got null too.
f
The solution of Bojan is working, you need to do some conversion.
🙏 1