Replacing an existing image in an Xcode Project - xcode

I am trying to update an Xcode project. The update is to replace an image that is displayed in a static window. I replaced the image being called, the new image has the same name and size, but when I open the window, the image does not fill the entire window like the original image did. I a new developer in general, but a total newbie when it comes to XCode. Any help would be appreciated.

Replacing an image file in a Xcode project can be done as:
Go to File in Xcode using the Project Navigator.
Right click the file and pick "Show in Finder"
Drag new file into as same folder as the old file. (make sure the old file and the file have the same name)
Say yes, you want to replace the file.
And your done.
Compile and run will show the new image. I've done this hundreds of times, usually updating placeholder images and never had any trouble.
As for your particular problem, you didn't describe the steps you used to replace the image, so I can't testify on that, but if you do the above and don't get the results you want it's going to be from a bad image file (different size, etc).

Related

How can I create a new file in Xcode without adding it to any target?

Sometimes I just want to create a plain text file for storing JSON or whatever.
Normally I would just press cmdN to create a new file in Xcode. But it always adds the created file to the project! That means I need to delete it from the project every time!
I thought that this was because I checked the target that I want to add the file to here:
So I unchecked "TestingArea" and created the file. But it still adds the file to the project!
I know that I can use the TextEdit app, but since I have lots of apps placed on the Dock, finding it takes a long time.
Any solutions?

How do I access images (for document icons) in an asset catalog in the Xcode 5 product preference editor

I think I'm literally on the last step before submitting a new Mac app, and I've been banging my head against a wall for the past few hours on what I think should be really, really easy.
I've designed document icons for the two different types of icons my app creates and works with. I created a new "Icon" in Images.xcassets, and dropped the appropriate files into the drop zones.
In the product editor -> Info, I go to where the document type information is, but when I try to enter in the icon name in the "icon" field of either the Document Types or Exported UTI section, the icon image just turns into a question mark—no options show up in the drop down menus for icons.
How do I get the images/icons in the asset catalog to show up in the editor? Alternatively, if I was going to enter that manually into the plist, what sort of format would I use to reference an Icon file from the asset catalog?
I know I'm probably missing an easy step here, but I can't see it!
To my knowledge, Xcode doesn't currently support using .xcassets for document icons. This is a little strange—the .xcassets editor clearly allows you to create new icons, but it doesn't generate .icns files, it just puts all the files in the same folder and uses a plist to manage them.
To create an icon for your document types, upload the 1024x1024 version of the icon to http://iconverticons.com/online/ to convert it to a .icns file. Alternatively, you could use a third-party tool to generate an .icns file with different images for different resolutions. There used to be a great tool included in the Developer Tools for doing this, but I can't seem to find it anymore.
Once you've got an icns file, add it to your project and you should be able to select it as the "Icon" for your Document Type or External/Internal UTI. Enjoy!
To be honest, it might be worth filing a bug about this. Xcode's development seems so strongly driven by iOS these days, they may not have noticed this yet!
I did it in the most easy way:
Add "New OS X Icon" to images.xcassets and name it "DocIcon", for instance.
Drag and drop images of your document icon
Just type "DocIcon" to icon name of your document
You will see question mark as document icon thumbnail. Don't care about. All will work fine after build and launch of application.
This is what worked for me, using Xcode 10 in 2019 (none of the other answers worked in my case):
Select asset catalog in Project Navigator
Right click on the left pane (list of assets) and choose App Icons & Launch Images ▶︎ New macOS Generic Icon (second option from bottom). Name it "Document". This will create a folder named "Document.iconset" in the asset catalog directory.
Populate all entries with your custom images. They must all be of the appropriate size (e.g., "16 x 16 #2x" must be 32 x 32 pixels, otherwise you will get yellow a warning icon over the image slot).
Navigate to the asset catalog folder, and use the command: iconutil -c icns Document.iconset (must match the name of the icon created in step #2). I took this command from Apple's documentation here (which by the way, also says some BS about Xcode "automatically creating an .icns file from your .iconset folder on build". Sure...).
Copy the newly created Document.icns file as a resource to your project.
Select the target, open the Info pane, and in both Document Types and Exported UTIs set your .icns file as the icon for the file type.
Hej, allesamme,
I had the same problem and have been researching it for days. I found a family of four solutions, the first three of which did not work for me: 1. using a .png file as the document type icon file; 2. using a manually created .icns file as the document type icon file; 3. the above solution, and 4. what I will describe here. Only the last one worked for me.
I tried following the spirit of the above advice and found that it didn't work, at least for my MacOS app. I'm on OS X 10.9.2 (13C64) running Xcode Version 5.1 (5B130a).
The current wisdom seems to be to create a directory in your workspace with a lower-case name and .iconset extension, in which one puts files with an icon_ prefix and the usual suffixes (16x16.png, 16x16#2x.png, 32x32.png, etc.)
In Product Editor's Info pane you can go into Document Types and associate the .iconset file with the Icon field. The icon image happily displays something reasonable. The build process builds a .icns file from that spec and copies it into your app.
I had an intermittent problem that the .icns file wouldn't build, which I traced to mistakenly haven included a 64x64 icon in the list. That's a no-no.
The current Apple dogma on this issue can be found in the official documentation, which covers some details I glossed over here. I didn't need to edit the Info.plist file directly: everything seemed to work from the interfaces provided in Xcode.
I have no idea which solutions work in which contexts, but thought I'd add throw more alternative on the fire for people to try out. — Jim Coplien

Interface builder file content missing

Am a new bie to IOS development. While working with some sample apps, my mac restarted and after opening xcode i found one interface builder file .xib marked as red. Double click on it shows no content at all. I tried deleting and adding it back from xcode but its not working.
I dont see the file in the project directory too, but when i replace it with old file, it says
an item with same name exists
but its not visible in finder.
Any help would be appreciated.
I am not sure what is a clean solution for this but a quick fix/workaround which worked for me is this:
Along with the error message 'an item with same name exists' you must be getting an id/number which is duplicated.
Open the xib file in any text editor (TextWrangler etc.). It is just an xml file.
Search for that number in the xib. You'll find multiple occurrences of that id.
Replace one of the occurrences with another number and make sure the new number you've added is not a duplicate.
Save this file and open in xcode. The error should be resolved.
Right click on one file in the project and it displays the showinfinder . Then it opens project folder in the finder. Check your file whether it is existing in that or not.

How do I add an icon to my Xcode project?

I have an Xcode project for Mac OSX, and I'd like to add an icon file (.icns) to my project and set it as the App Icon. How would I do this?
The key here is that you need an ICNS (icon set) file.
The right way to create this is described in the Human Interface Guidelines, and the details are covered in various user's guides and reference guides in Apple's maze of twisty little documentation, but I'll summarize it here.
There are third-party tools that can do this, as well as plugins for Photoshop, GIMP, Illustrator, etc., that can output a correct .icns file. But make sure, if you use such a thing, it's up to date, because Apple changes the rules all the time.
If you need to do it manually, here's what you do:
First, create a set of PNG files at different sizes. The exact list of what you need changes over time. See Provide the Correct Resources and Let OS X Do the Work if that link lasts longer than the current list; otherwise, search for it at http://developer.apple.com yourself. But, as of early 2013, it's 512x512, 256x256, 128x128, 32x32, 16x16, and #2x versions of each. All of them should have the sRGB color profile embedded in them. They should be named either icon_512x512#2x.png, icon_512x512.png, etc., or MyApp_512x512#2x.png, MyApp_512x512.png, etc. Put them all in a directory together named, e.g., MyApp.iconset.
"But wait! I just want an icon, I don't want all those sizes!" Well, you really do want all those sizes. Your 512x512 icon will look horrible when scaled down to 32x32. And on a Retina Mac, when your icon gets scaled up to double resolution, instead of getting sharper it'll just get jagged. Also, if you want to get into the App Store, Apple will reject you if you don't have them. But, if you insist, you can get away with just putting icon-512x512.png in the folder, and follow the rest of the steps, and it will work.
From the Terminal, cd into the parent directory, and type iconutil -c icns MyApp.iconset. You will get a file called MyApp.icns.
Now you can do the steps suggested by Douglas, and it will actually work. In Xcode, select your project in the Project Navigator, select your app target in the project sidebar, select the Summary tab, and drag MyApp.icns from Finder to the App Icon box.
This may not have any visible effect in the GUI, except to add MyApp.icns to the Project Navigator. In other words, you may still see the "?" icon. This seems to be a bug in Xcode 4.5. If you follow the out-of-date recommendations from the HIG two versions ago, Xcode always shows the icon, but if you follow the current HIG, it doesn't. Go figure. Hopefully Apple will fix that some day.
But for now, it doesn't matter. Build the project, and then look at MyApp.app, and it will have your icon in the Finder, on the Dock, etc.
Now, I know you don't want to draw the same picture in 10 different variations, you just want something simple. As long as you don't want to get into the App Store, you can get away with cheating, in two ways:
Scale the 512x512 (1024x1024 pixel "512x512#2x" if supporting hi res) image to all of the other sizes, using your favorite tool.
Create a .icns with nothing but the 512x512 image in the iconset.
The second one is simpler, and less cheat-y, and ultimately Finder is probably going to scale your 512x512 image as well as you would have anyway.
Finally, if you've manually edited your Info.plist or changed build settings (or you're using a project imported from a much easier version of Xcode), just dragging the image may not be enough. If you need to do the same steps manually, here they are:
MyApp.icns has to be in the Project Navigator as a file in your project. (You can drag it here from Finder.)
In Build Phases, the Copy Bundle Resources should include MyApp.icns. (You can drag it here from the Project Navigator.) (If you're not using the normal Build Phases for some reason, you need some other way to get it copied to Contents/Resources/MyApp.icns at build time.)
Your Info.plist should have an Icon file (raw name CFBundleIconFile) named MyApp, with no extension.
That's all there is to it.
In the project navigator, select an asset catalog.
Choose Editor > Add Assets > App Icons & Launch Images > New OS X Icon.
An empty OS X icon set is created, with an image well for each image representation in the set.
Drag icon file from the Finder to the appropriate image well in the set viewer.
Alternatively, you can add images by selecting an asset catalog, and choosing Editor > Add Assets > Import.
I am pretty sure you will have to put your icons into the project and then recompile. Let us know how it goes.

Save image in a folder and directly use XCode

I was wondering whether it is possible to save an image you just edited in Photoshop, and immediately it is useable in XCode, instead of dragging the image into XCode all the time.
You could create a folder reference to the location you are saving your images.
To do this, use the "Add Files to 'NameOfProject'" menu command, then select your folder. Ensure that the options are set as follows:
Then the images should appear in Xcode when you view the contents of that folder. When referencing them, you must use the name of the folder. E.g. [UIImage imageNamed:#"MyImages/image.png"];

Resources