Home > database >  How to display images in Muti-Platform Xamarin.Forms Project on iOS
How to display images in Muti-Platform Xamarin.Forms Project on iOS

Time:11-25

I've got a Xamarin.Forms Project containing an Android and an iOS Platform Project.

I've got my whole application working on Android and I am now struggling on the iOS part. I can't get my images to display on iOS.

I've followed the Microsoft guide on how to work with images on Xamarin.iOS, but it's simply not working.

I have created a minimum example from a new project and uploaded it to GitHub, it can be found here.

Output: On Android, the image is being displayed fine, on iOS, the screen stays empty. In addition to that, the logs I've added to AppDelegate.cs show, that the images cannot be found by using UIImage.FromBundle()

I've also checked the CSProject file of the iOS project, but it already contains the <ImageAsset> item groups.

I am on Visual Studio Professional 2022 (Windows) Version 17.4.1

Can someone please have a look into this? I am going crazy...

CodePudding user response:

I have test your project with the Visual Studio 2022 for mac. And I had the same results in the Android platform and ios platform. The small car icon will show at the top of the screen.

But for the iphone 14 pro simulator, which has a notch screen. The car icon almost be covered. So you can try to run it on the ipad or a device without notch screen to check the car icon will show or not.

In addition, I have checked your Assets.xcassets folder and the official sample on the github. There is no a such xxx_vector folder in it.

CodePudding user response:

Background information:

  • What's deprecated (but still works) is individual resource files (aaa.png, [email protected]), with no xcasset.
  • An xcasset containing those files is not deprecated. Nor is it likely to become deprecated in the future.

If you still want to test with .pdf containing vectors:

  • What is problematic about your setup is that you have TWO representations of car_settings. One with .pngs, one with vector pdf.
  • What happens if you remove the xcasset with .pngs, and rename the one with pdf to match the filename in it? (car_settings xcasset, with car_settings.pdf).
  • Close VS, and delete all .bin and .obj folders after making this change, to ensure VS correctly rebuilds with the vector version.

If this still fails, then you likely have encountered a bug. Add as an issue at github xamarin forms issues. Be sure to mention the versions of VS and Xamarin.Forms that has the problem.

  • Related