Images in Folder in UIImageView

Discussion in 'iOS Programming' started by ahan.tm, Sep 18, 2011.

  1. ahan.tm macrumors regular

    Joined:
    Jun 26, 2011
    Location:
    Florida
    #1
    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
     
  2. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #2
    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...
     
  3. ahan.tm thread starter macrumors regular

    Joined:
    Jun 26, 2011
    Location:
    Florida
    #3
    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.
     
  4. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #4
    In Interface Builder itself, you can't navigate through Groups/files, just with the String of the .png (totally sux at Xcode 4.x+)
     
  5. ahan.tm thread starter macrumors regular

    Joined:
    Jun 26, 2011
    Location:
    Florida
    #5
    So, I would need to hand code each UIImageView!!:eek:
     
  6. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #6
    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.
     
  7. ahan.tm thread starter macrumors regular

    Joined:
    Jun 26, 2011
    Location:
    Florida
    #7
    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"];
     
  8. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #8
    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.
     
  9. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #9
    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.)
     
  10. ahan.tm thread starter macrumors regular

    Joined:
    Jun 26, 2011
    Location:
    Florida
    #10
    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.
     

Share This Page