Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ahan.tm

macrumors regular
Original poster
Jun 26, 2011
141
0
Florida
Hi,

I am trying to set the images for my UIImageView in Interface Builder in Xcode 4. I added the images in folders and selected "Groups For Any Added Folders" but how do I navigate the folder/group filesystem to select them for my UIImageView?

Thanks
 
In the interface builder, select your UIImageView and look at the top right panel. There should be six icons, the fourth one should be a slider looking thing. Select the slider. Expand "Image View" just below, if it isn't automatically, and type the name of the Image file in the space labeled "Image".

A traditional file system doesn't really exist on iOS and the files you set up in Xcode are just for your convenience while developing... they don't reflect how your files will be set up in iOS on the device at all. On iOS, pretty much every file you add to your application is thrown in a big bundle. There are a few exceptions, but I don't think those are important for the purpose of your question...
 
In the interface builder, select your UIImageView and look at the top right panel. There should be six icons, the fourth one should be a slider looking thing. Select the slider. Expand "Image View" just below, if it isn't automatically, and type the name of the Image file in the space labeled "Image".

My images are in folders according to their color, and there are 6 files in each folder, and each file has the same name.

Example:
Red/+1.png
Blue/+1.png
etc.
 
Hand Code?
No, not at all? i think we're just on a different line.
If you have an UIImageView in Interface Builder, and you want to assign an image to it, (and you put in the imageString.png), you can't actually navigate through a "FileSystem Tree", like in other other IDE's, the only thing you can do. (unless someone can prove me wrong).
Red+1.png
Red-1.png
etc.

I do it different through code, I loop through a hardfolder with extensions.png. So then depending on the directory, I can change. but you want to stick to Interface Builder if you don't want to go there. Then you need to do like I said :)
Good luck.
 
Hand Code?
No, not at all? i think we're just on a different line.
If you have an UIImageView in Interface Builder, and you want to assign an image to it, (and you put in the imageString.png), you can't actually navigate through a "FileSystem Tree", like in other other IDE's, the only thing you can do. (unless someone can prove me wrong).
Red+1.png
Red-1.png
etc.

I do it different through code, I loop through a hardfolder with extensions.png. So then depending on the directory, I can change. but you want to stick to Interface Builder if you don't want to go there. Then you need to do like I said :)
Good luck.
So, You want me to swing an UIImage to each image and then select them in interface builder?

Would the code to set each UIImage be this:
Code:
UIImage *image = [UIImage imageNamed: @"cell.png"];
 
So, You want me to swing an UIImage to each image and then select them in interface builder?

Would the code to set each UIImage be this:
Code:
UIImage *image = [UIImage imageNamed: @"cell.png"];

You could just say
Code:
myImageView.image = [UIImage imageNamed: @"cell.png"];

And not worry about declaring it first... IDK, I just feel like it takes up extra space to always do that.
 
But.. You are now doing it by code again, and not by Interface Builder.
And If you're gonna do it by code, I would do it like the guy above me (artofwarfare).
assign the .image to a new autoreleased image pointer.
(if you don't understand, just like the second line he showed.)
 
Hi,

Thanks for all your replies, and I was finally able to get it working. I decided to use this code:
Code:
myImageView.image = [UIImage imageNamed: @"cell.png"];

This code is usable in my app, because the images will be changing at the users request.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.