How do you access Asset Catalog images from a UIImageView in Storyboard?

sdonaldsonsdonaldson CAMember ✭✭
edited July 2017 in Visual Studio

Working in VS2017 an iOS Xamarin.Forms app, so hopefully this question is in the right spot.

I created an Asset Catalog called LaunchImages that contains the PNGs required for the various iOS launch screen sizes.

In my LaunchScreen.storyboard I have created a UIImageView, but cannot set the Image property of that view to access/display the Asset Catalog.

Things I have tried:
1. Closing/reopening storyboard
2. Updating VS2017 (15.2; 26430.15)
3. Running VS2017 as Administrator
4. Making sure xcassets folder is not read only (per this: https://stackoverflow.com/questions/40644263/asset-catalog-doesnt-open-in-visual-studio)

I'm able to set the Image property to one of the existing resources in my project, but not to the asset catalog.

Do I also need to include each PNG image as a separate resource?

I'm following the guide here: https://developer.xamarin.com/guides/ios/application_fundamentals/working_with_images/displaying-an-image/ - getting stuck at "Displaying an Image in a Storyboards" Step 5.

Other possibly related threads:
https://forums.xamarin.com/discussion/33590/accessing-images-from-an-asset-catalog
https://forums.xamarin.com/discussion/96938/how-to-set-image-property-for-uiimageview-in-storyboard-editor

Answers

  • prashantvcprashantvc USXamarin Team Xamurai

    I attempted to reproduce this issue using this sample code with the latest Visual Studio 2017 Preview version 15.3, and I was unable to hit the problem. If this issue is still occurring for you, please attach a reproduction, ideally starting with a new template project and then adding just the code necessary to demonstrate the issue

  • sdonaldsonsdonaldson CAMember ✭✭

    Thanks Prashant - the issue is still occurring with my project, so I'll try to create a new template project and replicate that way.

  • sdonaldsonsdonaldson CAMember ✭✭

    The AssetCatalog works perfectly with that sample solution so it must be something wrong with my configuration... just not sure what. Maybe I'll try recreating the storyboard/asset catalog from scratch and seeing how it goes from there.

  • sdonaldsonsdonaldson CAMember ✭✭

    I'm back at this again. Have to contradict my last post. The AssetCatalog in the sample code is not working for me either.

    The drop down is populating with the images from the /Images folder in the solution, and not the images contained in the "Images" AssetCatalog. I thought the Images prefix meant the AssetCatalog was working... :/

    Recreating the storyboard/assetcatalog in my own solution had no effect.

  • I have the exact same issue and it's doing my head in.

    Just cannot get perfectly valid Image Asset Catalogs to be shown in the picklist for the Image property on my UIImageView...

  • ChrisEarlyChrisEarly USMember
    edited September 2017

    I'm having the exact same issue as the OP and Aaron and it is indeed driving me a bit crazy. My version of Visual Studio 2017 is 15.3.5. I'm trying to create a LaunchScreen.storyboard following the Xamarin documentation, but am unable to reference anything from an Asset Catalog no matter how many things I've tried. Help on this would be much appreciated!

  • ChrisEarlyChrisEarly USMember

    Update on the issue, at least my issue: The sample project referenced by Prashant doesn't show the Vector Image "Monkey" from the Images asset catalog in the Image dropdown of the Image View controls. I see that "PurpleMonkey" is referenced in MainStoryboard, as well as GreenMonkey.png (that's not in an asset catalog), but I don't see Monkey referenced anywhere.

    Are Vector Images in Asset Catalogs not supported (even though it's in the tutorial)?

  • ChrisEarlyChrisEarly USMember

    Just to wrap up my issue: The final snag I had was starting from an Empty Storyboard, rather than a Storyboard View Controller, since the Empty one was the recommended option in the developer.xamarin.com tutorial I was following "Working with Images: Launch Screens - Storyboard."

    I think the lack of a codebehind prevented the ImageView dropdown from seeing the available Asset Catalogs. I still couldn't use a Vector Image though, I had to provide three PNGs in the Image Set. But once I did all that I was able to select the Image Set from the Asset Catalog in the Storyboard's ImageView dropdown.

  • anveanve DEMember ✭✭✭

    I also had to remove the PDF and only use the three images. For me it was necessary to rename the image asset, so it could be found in the storyboard. Perhaps a naming issue here?

  • ClayBrinleeClayBrinlee USMember ✭✭

    I had the same thing using VS 2017 Ent. 15.6.4
    I tried all kinds of stuff until finally after doing the following it started working. I don't know exactly which change got it working so I'll just tell you every step I did.

    1) Created a 150x150px image named splash_logo.png
    2) Created a 300x300px image named [email protected]
    3) Created a 450x450px image named [email protected]
    4) I only added the 1x image to the image set
    5) I named the imageset the same as the 1x filename, so I named it splash_logo
    6) I edited the properties of the actual Imageset. Under device I set iPhone to true, then I set it back to false.
    7) Under misc I set Render As to "Original" then set it back to default.

    Now that it was working, I went ahead and added the 2x image and the 3x image to the imageset.

  • rebuild your ios solution and the image assets will show up in the drop drown

  • XigmondXigmond USMember ✭✭

    Hi, Im havin the same issue creating an splash screen in my project
    I deleted the storyboard and created an empty one and added the UIImageView according to the Microsoft Tutorial , created the image asset and assigned the needed image sizes ,
    the most disturbing thing is in all the tutorials every where they just go to the imageview properties and all the images are there somehow !! but when i do the same thing it shows the OpenFileDialog rather than a list of my image assets.

    anyone knows whats wrong?

  • XigmondXigmond USMember ✭✭

    ... By the way what is the launch Screen property and Launch Image set , does that have anything to do with this issue ?

  • LobboLobbo GBMember ✭✭

    @Xigmond said:
    ... By the way what is the launch Screen property and Launch Image set , does that have anything to do with this issue ?

    This was a bug in visual studio which was fixed in 15.9.4, so an update should fix that for you if you're still facing the issue.

Sign In or Register to comment.