简体   繁体   English

UIButton图像在模拟器上的尺寸不正确

[英]UIButton image doesn't have the right size on simulator

I having a problem while setting an image on a UIButton. 在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. 如您在第一张图像上看到的,左侧是Xcode上图像的显示方式,右侧是较小的模拟器上的图像显示方式。

The second image is for reference, it shows how is displayed on different screen sizes on Xcode. 第二张图像仅供参考,它显示了如何在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 创建大小为100 x 100像素的img1.png
  • Create another image img1@2x.png with 200 x 200 pixels 用200 x 200像素创建另一个图像img1@2x.png
  • Add them both to your project 将它们都添加到您的项目中
  • In your button use img1 in storyboard 在您的按钮中,在情节提要中使用img1
  • See how it displays in your iphone 5 and iphone 6 simulators. 查看它在iphone 5和iphone 6模拟器中的显示方式。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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