Storyboard problem

Discussion in 'iOS Programming' started by ildandi, Nov 7, 2012.

  1. ildandi macrumors newbie

    Joined:
    Nov 7, 2012
    #1
    In my app, in XCode I show Resources folder with all images: Resources/iphone

    image@2x~iphone.png
    image~iphone.png

    In my storyboard I've all views but in proprieties I show that images have naming like this:

    "image.png"

    (all images without ~iphone.png)

    is this OK? or is it a problem?


    Strange thing is this:

    In Storyboard I show "?" when I've images because can't show linked image (wrong name, missed ~iphone e @2x~iphone)

    but

    When I build and run app on device I show all images OK!

    Where is it the problem?

    Thanks
     
  2. Reason077 macrumors 68000

    Reason077

    Joined:
    Aug 14, 2007
    #2
    You should not specify the "@2x~iphone.png" part of the filename in your code or in interface builder. Just "image".

    If your project works on multiple devices, you'll likely have several instances of each file depending on whether it's for iPhone, iPad, retina, or non-retina display. In some cases you should omit the "~iphone" part, if you want to use the same resource regardless of whether its an iPhone or iPad.

    At runtime, iOS will select the correct file based on the device.
     
  3. ildandi thread starter macrumors newbie

    Joined:
    Nov 7, 2012
    #3
    Can you help to understand how to set right structure!

    Do you mean that I've to set

    imagename.png

    and not
    imagename@2x~iphone.png
    imagename~iphone.png



    App is for iPhone, I don't have selected universal device but only iPhone.
    What do you mean with Several Instances of each file?
    I've a single Storyboard (splitted in 2 languages)


    Are you talking about StoryBoard?


    Why in Storyboard I show image missed?? I don't show image but "?" symbol

    Thanks
     
  4. Reason077 macrumors 68000

    Reason077

    Joined:
    Aug 14, 2007
    #4
    Yes, but for the image to show up in Interface Builder, you do have to have a file named the same as what you specify (if not, you'll get the "?" symbol as you mentioned). But at runtime, the OS will select the correct version automatically depending on what device it's running on.

    Say you select "imagename~iphone.png" as the image file in Interface Builder. But when you run it on a retina iPhone device, it will actually automatically switch to using "imagename@2x~iphone.png" instead, if it is available.

    Say you later decided to port your app to iPad as well. Then you might have an ~iPad as well as an ~iPhone variant, if you wanted to use different resources in the iPhone vs the iPad versions.

    The same rules apply regardless of whether you're using storyboards, regular .xibs, or [UIImage imageNamed:]
     
  5. ildandi thread starter macrumors newbie

    Joined:
    Nov 7, 2012
    #5
    Great!!! now it's clear

    So I need
    imagename.png (for storyboard images)
    imagename@2x~iphone.png (for retina)
    imagename~iphone.png (for not retina)
    .. what name for iPhone5?

    is it OK to save these images in:
    appname/image/iPhone?



    Do you mean in views layout created in StoryBoard?
    And keeping all images in same iPhone folder?



    ~iPad images will be saved in appname/image/iPhone?
    Is it XCode that automatically find and search right device images in my App file system structure?


    I mean that I could use iPhone or iPad folders.... or other named and XCode will search and match right images? Or is there a right folder naming and position?

    Thanks
     
  6. Reason077 macrumors 68000

    Reason077

    Joined:
    Aug 14, 2007
    #6
    There's no difference for iPhone 5. It uses the same resources as iPhone 4 (i.e. "~iphone@2x")

    The folder layout in your project makes no difference. You can put the images wherever you like. When XCode builds your project, it lumps all the resources together into one folder anyway.

    Not really. It's iOS that figures out the right resources to load, at runtime.

    A far as folders go, you can use whatever layout/names makes sense for you. But the files themselves must be named correctly.
     
  7. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #7
    Just be sure you understand the difference between folders and groups in Xcode.
     
  8. ildandi thread starter macrumors newbie

    Joined:
    Nov 7, 2012
    #8
    You're right could be that I a little confused about folders and resources in Xocde :-(
    Can you tell me differences.... and when user folders?

    Thanks
     
  9. ildandi thread starter macrumors newbie

    Joined:
    Nov 7, 2012
    #9
    Can you help me understsand when use Folders and when Resources??

    I think that I'm little confused about this

    Thanks
     
  10. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #10
    Do you mean groups and not Resources?

    Anyway, here's a blog article you might want to read: Xcode Groups vs. Folder References

    P.S. Most current-day iOS Xcode projects no longer create a Resources group. Do yours have it? If so, what version of Xcode are you using?
     

Share This Page