简体   繁体   English

如何使用尺寸类在Xcode中设置UIImageView对象

[英]How to use size classes to set UIImageView object in Xcode

I am working on an universal application, and in that I am using 'size classes' for setting images in UIImageView. 我正在开发通用应用程序,并且正在使用“大小类”在UIImageView中设置图像。 I have tried it but it is looking same in size on iPhone and iPad. 我已经尝试过了,但是在iPhone和iPad上看起来都一样。

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. 设置前,后,上,下约束的约束,也可以根据需要设置高度和宽度的约束。

  • Share your email i will email you a demo application for this using your image 分享您的电子邮件,我将使用您的图像通过电子邮件将其演示应用程序发送给您

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

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