[英]How to use size classes to set UIImageView object in Xcode
you just have to give the your UIImageview size of your UIView and than set its ContentMode to AspectFit like these...i hope it helps.. 您只需要提供UIView的UIImageview大小,然后将其ContentMode设置为AspectFit即可,...希望对您有所帮助。
imgView=[[UIImageView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height)];
[imgView setContentMode:UIViewContentModeScaleAspectFit];
[self.view addSubview:imgView];
First you need to switch to different size classes for iPhone and iPad 首先,您需要切换到iPhone和iPad的不同尺寸级别
add an imageView in Size Class any any so that it is available in any size classes 在size类中添加任意一个imageView,以便在任何大小类中都可用
use width compact and height regular Size Class for iPhone 为iPhone使用宽度紧凑和高度常规的 大小类
use width regular and height regular for iPad 为iPad使用常规宽度和常规高度
In both size classes add constraints leading, trailing, top, bottom . 在这两个大小类中,添加前,尾,上,下约束。
These constraints are for background image. 这些限制适用于背景图像。 For others you will have to change it as per your requirement. 对于其他人,则必须根据需要进行更改。
I hope you already have different images for iPhone and iPad including retina images. 希望您已经为iPhone和iPad使用了不同的图像,包括视网膜图像。
Set size class with respect to device and oritentation 根据设备和方向设置尺寸等级
You can take help to change size classes from the following link Size class base on different devices How change size classes 您可以从以下链接获取帮助来更改尺寸类别,这些链接基于不同设备的 尺寸类别如何更改尺寸类别
Set constraints for leading, trailing, top and bottom constraint you can also set height and width constraints based on your requirement. 设置前,后,上,下约束的约束,也可以根据需要设置高度和宽度的约束。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.