4

I have created a screen with 2 images on it (150 x 150 pixels) designed to take up most of the screen. This looks fine in the simulator, but when I actually run the app on the device, the images have shrunk down to become very tiny. I assume that the device sizes are the size of the actual image itself.

I used very high quality images so you can't notice that the image has been stretched on the simulator.

Is there something that I can use to ensure that I am always going to use the 150x150 size?

Many thanks

Jon

3
  • do you use imageNamed? Do you support retina (images with @2x suffix before extension)? Show some code! Commented Aug 16, 2014 at 10:23
  • Could be simply you have the constraints set up wrong. Can you please provide more detail, Are you using storyboard?, Autolayout? have you used any code to set the frame of the UIImageView, is your simulator 4inch, device 3.5inch? Providing as much relevant detail as possible will allow people to potential show you where you are going wrong. Commented Aug 16, 2014 at 15:11
  • Thanks Gents. I am not using any code at all. I simply dragged a button into Storyboard and assigned a local image to it. I have not set up an image with a @2x suffix either. I am using Autolayout, but I have configured nothing (i.e. I'm using defaults). It doesn't seem to be autolayout'ing anything. When I rotate the device, I simply lose the bottom of the screen so I assume it's not working anyway. Commented Aug 16, 2014 at 19:21

2 Answers 2

3

from what you described, this can be fixed by simply setting the constraints for each object on your storyboard.

To give you an example of how to do this, I've added two UIImageView objects to the storyboard. Select the first object and press the constraints button at the bottom like in the picture below, and you will need to make sure at least 4 constraints have been set. Specifically, check the HEIGHT, WIDTH and select the distance to LHS and distance to TOP by selecting the corresponding struts which will change to a highlighted orange colour (see picture)

enter image description here

Once this has been done, press the 'Add 4 Constraints' button at the bottom. Then repeat this with the second UIImageView object.

When the constraints are properly set (with no conflicts) they will be visible if you select the object, and the constraint lines will be blue (see pic below)

enter image description here

By following these steps for adding objects to your storyboard, then this will solve the issue of the squashed image on the device. Further reading on configuring auto-layout constraints would be very useful.

I hope this helps

Sign up to request clarification or add additional context in comments.

3 Comments

I will have to digest this. I am currently using buttons so the interface is a little different. If I use UIImages, then I will have to change the action selection since it is different for a button. I will let you know how I get on - thanks.
@JonM Are you setting an image within a UIButton? No matter what object, UIImageViews, UIButtons, UIlabels etc, they can all be set using constraints as explained above. If you are setting the UIButton with an image, using the above method then setting the UIButton's image as setBackgroundImage: (as opposed to setImage:) will also help.
Thanks @Jeely. Sorted. I added the width and height constraint and it looks on the iPhone exactly as it does in the simulator.
1
  1. Just check your image name, because device is case sensitive but simulator is not.After changing the image name,if it will work then fine.
  2. you can add a 2x version of image(as: [email protected]).
  3. Remove installed app from device, and run it again.

I think it will help you.

1 Comment

Thanks Monikanta - but '1' can't be possible. I am using files that are contained within the project and simply choosing them as a drop-down. It's good to know for the future when I am coding the embedding manually though.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.