How to set image in storyboard from framework assests
Asked Answered
I

2

8

In My Project, there is one framework project and this framework project has images in the assets catalog..

I want to use theses images using the storyboard of my main project.

I can use the images in class files by defining the bundle of the framework like this,

myImageView.image = UIImage(named: "img1", in: Bundle.init(identifier: "com.abc"), compatibleWith: nil)

but not in the storyboard. so Can I use it in storyboard or I have to go using code only ?

Ice answered 9/2, 2018 at 11:8 Comment(1)
use for code onlyTheodosia
Q
5

You cannot use assets of other frameworks directly, but you can add the assets to your main target as reference:

"Add Files to Project.xcodeproj..."

You will then be able to choose the images of the assets container in the attributes inspector of image views and buttons.

Quemoy answered 9/2, 2018 at 15:11 Comment(2)
This seems to work. Does the "Add as reference" part also imply that the images won't be duplicated in the binary, or only that they aren't copied to the main project folder (and simlinked instead)?Gerick
Hi @Nicolas Miari. I'd very much like to know the answer to this too, so I actually posted a question dedicated to it here, in case you're interested: #55859940Withe
T
2

Please follow below steps to user framework image assets.

  • Create bundle resource for your framework project

  • Add your required images into that bundle resource

  • Build your framework and drag that framework into your project

  • Also drag and drop that bundle resource into your project from framework package.

  • Use any images into your storyboard which you added into the bundle resources.

Please refer below image for more details.

enter image description here

Tish answered 12/2, 2018 at 8:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.