Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding Resources to a MonoTouch project

I am a new user of MonoTouch and wondering how to add image files to a project. None of the ways described work. The MonoTouch Wiki says to right-click the project and a menu should appear allowing one to "add" new files. There is no such right-click menu that I see.

Also, someone posted a workaround where a dummy Xcode project is created using the same folder destination as the MonoTouch application and then Xcode would establish the Resources folder and allow for the import of resource files (in my case a .JPG file).

I am not even to the point of needing to attach the image file to a control using Interface Builder; I mean: I can't even get the image file into my MonoDevelop project.

I've also tried creating a Resources subfolder inside my project folder and dropping the image file in there. No luck.

Can anyone provide a thorough procedure for adding resources to a MonoTouch project? Much appreciated.

like image 228
shaggy Avatar asked Mar 30 '11 15:03

shaggy


1 Answers

You should right-click on your project in the Solution pad:

Adding files to project

The context-menu is there, trust me. The project is just below the solution.

After that, you have to set your image file's Build Action to Content, again by right-clicking on the image file this time:

Build Action to Content

And to use the image from your code, you type:

UIImage myImage = UIImage.FromFile("image.jpg");

And you are all set! You can create all the folders you want in the project, but NOT a folder named "Resources". You will get an error upon compilation. In MonoTouch 3.2.5 at least...

like image 88
Dimitris Tavlikos Avatar answered Oct 21 '22 01:10

Dimitris Tavlikos