https://kotlinlang.org logo
#ios
Title
# ios
t

Trond Tunheim

02/04/2020, 12:01 PM
Hello ! I'm trying to load an image from Assets.xcassets into UIImage
val image = UIImage("mypin")
The file mypin.png is copied into Assets.xcassets in Xcode . This doesn't work , it fails to load the image. Anyone that has any thoughts on how to do this correctly?
r

Romain Dubreucq

02/04/2020, 12:23 PM
Hello, are you using init(named: String) initializer?
t

Trond Tunheim

02/04/2020, 12:27 PM
No, not sure how I would use that ?
r

Romain Dubreucq

02/04/2020, 12:29 PM
try something like
val image = UIImage(named: "mypin")
t

Trond Tunheim

02/04/2020, 1:15 PM
Ok, Tried that, but the only parameter accepting a String as input is "contentsOfFile:" . If i try
UIImage(named: "mypin")
it will not compile.
r

ribesg

02/04/2020, 1:35 PM
UIImage.imageNamed("mypin")
r

Romain Dubreucq

02/04/2020, 1:37 PM
I thought he was using Swift 🙃
t

Trond Tunheim

02/04/2020, 2:14 PM
My bad, should have said it was Kotlin. @ribesg: Thank you !!
2 Views