简体   繁体   中英

Why is my UIButton Image size different in Simulator and Device?

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

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)

在此输入图像描述

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)

在此输入图像描述

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

  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: yourImage@2x.png).
  3. Remove installed app from device, and run it again.

I think it will help you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM