Xamarin.Forms: iOS local images don't work.

Hi. I'm using Xamarin.Forms for tabbed view with local icon.

I've downloaded icons from "material icon" website, added to Resources in Android and with App Catalog in iOS.

In Android, tabbed viw works fine. In iOS, always get a runtime exception.

Unhandled Exception:

System.Exception: Could not initialize an instance of the type 'UIKit.UIImage': the native 'initWithContentsOfFile:' method returned nil.
It is possible to ignore this condition by setting MonoTouch.ObjCRuntime.Class.ThrowOnInitFailure to false..

Maybe the library FFImageLoading can't find the icon.

Any idea?

I've noticed that in PCL I need to call the icon with the name of the resources without extension (*.png).
But from that website, icons are named differently for Android and iOS.
For example,
Android (drawable): icon_home_black (.png)
iOS (resources): icon_home (.png)

Maybe is this the real problem? I need to rename them in the same way?

Answers

  • seanydaseanyda GBMember ✭✭✭✭✭

    Have you right clicked on the image and hovered over "Build Action" and set it to a "BundleResource"?

  • AbhumMumbhauAbhumMumbhau USMember ✭✭

    @seanyda thanks for your reply.
    But I can't understand your comment.
    I've added a new Asset Catalog with option "Image set", then I added a vector (pdf) and the three (x1, x2, x3) images.
    I know that vector OR images do the same final things, but no one of the two works.

    I can't understand your comment.

  • seanydaseanyda GBMember ✭✭✭✭✭
    edited September 2017

    @AbhumMumbhau said:
    @seanyda thanks for your reply.
    But I can't understand your comment.
    I've added a new Asset Catalog with option "Image set", then I added a vector (pdf) and the three (x1, x2, x3) images.
    I know that vector OR images do the same final things, but no one of the two works.

    I can't understand your comment.

    Just move the Image to the "Resources" folder and set it as a "BundleResource" and you will be able to refer to it in code.

Sign In or Register to comment.