简体   繁体   English

iOS:所有设备的图片自动调整大小

[英]iOS: Image auto resize for all devices

我正在尝试使用自动布局和尺寸类来调整图像的大小,但我似乎无法为iPhone 6+调整图像的大小,与iPhone 4或5相比,该图像很小。这是我第一次使用自动布局,因此我很友善对如何做感到困惑。

For all Iphone ,size classes is compact width and Regular height 对于所有Iphone,大小类均为紧凑宽度和常规高度

so select this and after that add 4 constraint 所以选择它,然后添加4个约束

  1. Leading 领导
  2. Trailing 尾随
  3. Top 最佳
  4. Bottom to your super view 从底部到您的超级视图

You can replace childView to your imageView.... 您可以将childView替换为imageView。

childView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin;

// vertical
childView.autoresizingMask = UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;

// both
childView.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;

have you tried using the previewer in xCode, its part of the assistant editor and will probably help. 您是否尝试过在xCode中使用预览器,它是助手编辑器的一部分,可能会有所帮助。

There is a guide here: http://www.dummies.com/how-to/content/how-to-autosize-an-image-with-auto-layout-for-your.html 这里有一个指南: http : //www.dummies.com/how-to/content/how-to-autosize-an-image-with-auto-layout-for-your.html

Add "proportional width" and "proportional height" to superview and make "center horizontal" and "center vertical" or anywhere you want to position. 添加“比例宽度”和“比例高度”以进行超级视图,并使“水平中心”和“垂直中心”或要定位的任何位置。 And once check the content mode of image to "ScaleAspectFit" or anything else which makes the image bigger. 并一旦检查图像的内容模式为“ ScaleAspectFit”或其他会使图像变大的内容。 If your image is of small size then it will show smaller on content mode "Center". 如果图像尺寸较小,则在内容模式“居中”中图像将显示较小。 Or use big images for all size devices. 或对所有尺寸的设备使用大图像。 Make sure you are using @2x and @3x images. 确保您使用的是@ 2x和@ 3x图像。

禁用Size类,然后通过按Control +拖动imageview将约束添加到superview并将其添加到约束。Leading Trailing Top Bottom

Just put constraints on image view, to 0 from all the edges. 只需将约束放在图像视图上,将所有边缘都设为0。 Don't add any more constraint. 不再添加任何约束。 It will stretch and shrink according to device that you use. 它将根据您使用的设备拉伸和收缩。 Regards 问候

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

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