Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set image in storyboard from framework assests

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 ?

like image 965
Shreyank Avatar asked Feb 09 '18 11:02

Shreyank


People also ask

How do I add assets to Xcassets?

Open your XCode Project. Just go to File -> Add Files to... (your Project) -> Assets. xcassets and you are good to go!


2 Answers

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.

like image 140
sundance Avatar answered Nov 15 '22 04:11

sundance


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

like image 45
Mobile Team iOS-RN Avatar answered Nov 15 '22 04:11

Mobile Team iOS-RN