简体   繁体   中英

UIButton image doesn't have the right size on simulator

I having a problem while setting an image on a UIButton. Check the image below:

在此处输入图片说明

在此处输入图片说明

As you can see on the first image, on the left side is how the image is displayed on Xcode and on the right side how is displayed on the simulator, which is smaller.

The second image is for reference, it shows how is displayed on different screen sizes on Xcode.

Any ideas on what is going on?

I just added a button to the view and this button has constrains on all sides, just in case anyone is wondering.

Thanks

Just a hunch but it may be something to do with retina and non-retina image sizes. Try this.

  • Create img1.png of size 100 x 100 pixels
  • Create another image img1@2x.png with 200 x 200 pixels
  • Add them both to your project
  • In your button use img1 in storyboard
  • See how it displays in your iphone 5 and iphone 6 simulators.

尝试在图像名称后添加@ 2x

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