Adding Resources to a MonoTouch project - image

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.

You should right-click on your project in the Solution pad:
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:
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...

Related

Why the Resources direrctory is not visible on my project navigatior

I just started learning SwiftUI and trying to follow the steps of the Building lists and navigation example from Apple. Although copied and existing on the project directory, I noticed the Resources directory is not visible in my project navigation on Xcode.
The build is successful, but since the app tries to read landmarkData.json file from that directory, it throws:
Could not find landmarkData.json in main bundle.
Why doesn't the Resources show up on Xcode? How can I fix this issue?
Thank you so much
Here's some things you can verify :
Verify if the clock is selected in the search bar. If so, de-select it.
Try deleting the Ressources folder in your projet files. Then, drag and drop it in your files navigator (left panel in xcode).

How to include support documents in xcode cocoa app?

In iOS version of app, sample/template files are added to Xcode in a group and then become a directory of that name within the app bundle. Easy enough.
What is the Cocoa equivalent? When I try the same thing, Xcode (Swift 3) fails on build with a "Command /usr/bin/codesign failed with exit code 1". How does one add support files (or directory of files) to a Cocoa app?
In macOS, I guess you mean that, every App creates a Resources Folder inside the NSBundle. Just check with right click "Show Bundle Content".
If you add resources to Xcode, just by dragging the file anywhere in your project navigation, will be asked to copy that file if needed.
I usually create a group with Supporting File, but thats arbitrary, because it has nothing to do with the file structure inside the project folder on disk nor with the product package.
To create groups just right mouse and select group.
This copies the file inside the Xcode project Folder. And if you choose to add target, then the file will be included to that Resource folder.
You can ask for that File with:
let bundle = Bundle.main
let path = bundle.path(forResource: "Test", ofType: "txt")
Edit
if you have to code sign your resources, then ope the copy files menu in Build Phases, add with the plus button your resource and check code sign on copy. This should provide a proper signing for your resource.
Hope it helps!

Changing the name of main folder in Xcode project

This is not the first time I've had trouble with this and I suspect not the last time either. Despite having learned many frameworks inside out I still find the organizational structure of a simple xcode project elusive. I simply wanted to retitle a project from CATouchSynth to ABTouchSynth. A while ago I discovered that if you click on the Project folder in project navigator and than change the name in the Identity and Type section it will rename many of the relevant files and directories to the new name. However, there is one main folder inside the folder on your computer that doesn't change and still has the old name. I could see no way to change this folder name through Xcode and so I renamed it manually from finder. This turned all of my source files and assets red so I manually "relinked" them in xcode and they are now non-red and seemingly linked with the newly named folder. However I am getting several compile-time errors talking about the old folder name but I have no clue what Xcode is referring too. The errors look like this
It seemed as if derived data was an issue so I deleted the derived data folder from Xcode and I still get these errors. Has anyone experienced this before and what can I do to ressurrect my project?
Note: Before doing any changes do backup your project folder. This is seriously recommended.
Follow the steps below to rename the source folder of your project –
Close XCode.
Rename the Source Folder.
Right click the project bundle .xcodeproj file and select “Show Package Contents” from the context menu. Open the .pbxproj file with any text editor (Xcode).
This step should be done with extreme caution. Search and replace any occurrence of the original folder name with the new folder name.
Save and Close the file.
Open XCode project.
The error is happening at build time during the compile phase, so you will have to go into the app target's Compile Sources build phase, remove all those .m files, and add them again.

How to transfer published resources from CocoStudio to Xcode?

using CocoStudio 2.0.6 and Xcode 6.1.1 on MAC inside VMware. After publishing in CocoStudio I open Xcode and "Add Files to myProject" with the "Copy items if needed" option checked. Then I have the folder myProject/res created by CocoStudio inside the myProject/Resources folder used by Xcode. Using CSLoader in HelloWorldScene.cpp works fine and I see the scene in the simulator. Runs ok also in Eclipse on Android emulator.
If I go back to CocoStudio and make changes like adding a sprite to the scene then I need to repeat the whole process of publishing, delete them Resources/res folder in Xcode and add it again. It is faster to delete the whole folder instead of adding new files into it and delete the ones not used any more.
My question is: am I doing it the right way or is it there a better way for Xcode to automatically see modifications to the resources made by CocoStudio?
Like when I use Eclipse and build the project, the resources in the myProject/proj.android/assets folder are automatically updated with the resources from the myProject/Resources folder.
Thank you.
You can make a resources folder in iOS app a symbolic link to the main Resources folder.
Remove the proj.ios_mac/Resources folder. Then go to your main app folder and execute:
ln -s ../Resources proj.ios_mac/Resources

Set application icon from resources in VS 05

I know I can add a icon to the Resources.resx file of a project and then reference that icon from within the code.
How do I set the icon of the entire EXE from the resources? All I see is a place to browse for another file. I want to use the current icon file that I have in my resources and not have to have a duplicate file in my project...
thanks
The way that the adding of an application icon is that you must select it from the local file system, and then it is embedded into the application at build time. As far as I know it is not possible to have it first pull from a resource file.
One solution I always use to prevent duplicate file references, is to create a solution folder such as "Project Dependencies". And then all refereces are made from that folder, so when building it pulls from the Project Dependencies folder.
This would work for resource files also, just copy them to the solution folder first and then drag them into your resource.
And for the assembly icon, just browse to the Project Dependencies folder as well.
Good Luck!

Resources