简体   繁体   English

使UI按钮的图像背景缩放到iPhone大小

[英]Making UI Button with image background scale to iphone size

in one of my views I have a full screen button with an image as a background set with my story board, when running on a four inch screen the image looks fine but on a 3.5 the image is cut off by the lack of screen real estate. 在我的一个视图中,我有一个全屏按钮,其中一个图像作为故事板设置为背景,在四英寸屏幕上运行时,图像看起来不错,但在3.5英寸上,由于屏幕空间不足,图像被切断了。 Is it possible for the image to re size to fit either screen or a way I can set the image in the code or storyboard for it to look proper on both screen? 图像是否可以调整大小以适合任一屏幕,或者我可以在代码或情节提要中设置图像以使其在两个屏幕上看起来都正确的方式? Thanks 谢谢 好人

问题(已终止)

Depending on your requirements you have two possible solutions: 根据您的要求,您有两种可能的解决方案:

imageView.contentMode = UIViewContentModeCenter; // Other options too...
imageView.clipsToBounds = YES;

OR create two different image assets and load via code something like: 或创建两个不同的图像资产并通过类似以下代码加载:

if ([UIScreen mainScreen].bounds.size.height == 568)
{
     // Load tall image
}
else
{
     // Load short image
}

是的,有许多方法可以自动调整大小。以下是可能帮助您的链接LINK_1 LINK_2

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

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