xcode iOS:所有设备的图像自动调整大小
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31000975/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
iOS: Image auto resize for all devices
提问by u_kami
I'm trying to resize my image using auto layout and size classes but I can't seem to get it resized for iPhone 6+ the image is small compared to iPhone 4 or 5. It's my first time with auto layouts so I am kind of confused on how to do it.
我正在尝试使用自动布局和大小类来调整我的图像大小,但我似乎无法为 iPhone 6+ 调整它的大小,与 iPhone 4 或 5 相比,图像很小。这是我第一次使用自动布局,所以我很友善对如何做到这一点感到困惑。
回答by Kishore Suthar
For all Iphone ,size classes is compact width and Regular height
对于所有的 Iphone,size classes 是紧凑的宽度和常规的高度
so select this and after that add 4 constraint
所以选择这个,然后添加4个约束
- Leading
- Trailing
- Top
- Bottom to your super view
- 领导
- 尾随
- 最佳
- 底部到您的超级视图
回答by Rohit suvagiya
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;
回答by Christian
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
回答by Mahesh Agrawal
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. 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.
将“比例宽度”和“比例高度”添加到超级视图并使“中心水平”和“垂直中心”或您想要定位的任何位置。一旦将图像的内容模式检查为“ScaleAspectFit”或其他任何使图像更大的内容。如果您的图像尺寸较小,则它会在内容模式“中心”上显示较小。或者为所有尺寸的设备使用大图像。确保您使用的是 @2x 和 @3x 图像。
回答by vp2698
Disable Size class and then add the constraint by control+drag imageview to superview and add that constraints Leading Trailing Top Bottom
禁用 Size 类,然后通过 control+drag imageview 将约束添加到 superview 并添加该约束Leading Trailing Top Bottom
回答by Vladimir Sukanica
Just put constraints on image view, to 0 from all the edges. Don't add any more constraint. It will stretch and shrink according to device that you use. Regards
只需在图像视图上设置约束,从所有边缘到 0。不要再添加任何约束。它会根据您使用的设备拉伸和收缩。问候