UIImage 和 UIImageView 的区别 [英] Difference between UIImage and UIImageView

查看:13
本文介绍了UIImage 和 UIImageView 的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

UIImageUIImageView 有什么区别?谁能举例说明一下?

What is the difference between UIImage and UIImageView? Can someone explain it with an example?

推荐答案

示例:

UIImage *bgImage = [UIImage imageNamed:@"Default@2x.png"];
UIImageView *backgroundImageView = [[UIImageView alloc] initWithImage:bgImage];
backgroundImageView.frame = [[UIScreen mainScreen] bounds];

UIImage 概述:

UIImage 对象是显示图像数据的高级方法.你可以从文件、Quartz 图像对象或原始图像创建图像您收到的数据.UIImage 类还提供了几个选项使用不同的混合将图像绘制到当前图形上下文模式和不透明度值.

A UIImage object is a high-level way to display image data. You can create images from files, from Quartz image objects, or from raw image data you receive. The UIImage class also offers several options for drawing images to the current graphics context using different blend modes and opacity values.

图像对象是不可变的,所以你不能改变它们的属性创建后.这意味着您通常指定图像的初始化时的属性或依赖图像的元数据提供属性值.然而,在某些情况下,UIImage 类提供了获取图像副本的便捷方法使用属性的自定义值.

Image objects are immutable, so you cannot change their properties after creation. This means that you generally specify an image’s properties at initialization time or rely on the image’s metadata to provide the property value. In some cases, however, the UIImage class provides convenience methods for obtaining a copy of the image that uses custom values for a property.

因为图像对象是不可变的,它们也不提供直接的访问他们的底层图像数据.但是,您可以获得 NSData包含图像的 PNG 或 JPEG 表示的对象使用 UIImagePNGRepresentationUIImageJPEGRepresentation 的数据功能.

Because image objects are immutable, they also do not provide direct access to their underlying image data. However, you can get an NSData object containing either a PNG or JPEG representation of the image data using the UIImagePNGRepresentation and UIImageJPEGRepresentation functions.

系统使用图像对象来表示使用支持设备上的相机.要拍照,请使用UIImagePickerController 类.将图片保存到已保存的照片"相册,请使用 UIImageWriteToSavedPhotosAlbum 函数.

The system uses image objects to represent still pictures taken with the camera on supported devices. To take a picture, use the UIImagePickerController class. To save a picture to the Saved Photos album, use the UIImageWriteToSavedPhotosAlbum function.

UIImageView 概述:

UIImageView 提供了一个基于视图的容器,用于显示单个图像或用于为一系列图像设置动画.为了动画图像, UIImageView 类提供控件来设置动画的持续时间和频率.您也可以开始并自由停止动画.

An UIImageView provides a view-based container for displaying either a single image or for animating a series of images. For animating the images, the UIImageView class provides controls to set the duration and frequency of the animation. You can also start and stop the animation freely.

新的图像视图对象被配置为忽略用户事件默认.如果您想处理自定义子类中的事件UIImageView,您必须显式更改userInteractionEnabled 属性为 YES 初始化对象后.

New image view objects are configured to disregard user events by default. If you want to handle events in a custom subclass of UIImageView, you must explicitly change the value of the userInteractionEnabled property to YES after initializing the object.

UIImageView 对象显示其中一张图片时,实际行为基于图像和视图的属性.如果图片的 leftCapWidthtopCapHeight 属性都是非零,然后图像根据那些值拉伸特性.否则,图像将被缩放、调整大小以适合,或根据 contentMode 属性定位在图像视图中风景.建议(但不是必需)您使用图像都是一样的大小.如果图像大小不同,则每个将根据该模式单独调整以适应.

When a UIImageView object displays one of its images, the actual behavior is based on the properties of the image and the view. If either of the image’s leftCapWidth or topCapHeight properties are non-zero, then the image is stretched according to the values in those properties. Otherwise, the image is scaled, sized to fit, or positioned in the image view according to the contentMode property of the view. It is recommended (but not required) that you use images that are all the same size. If the images are different sizes, each will be adjusted to fit separately based on that mode.

UIImageView 对象关联的所有图像都应使用相同的规模.如果您的应用程序使用不同比例的图像,它们可能渲染不正确.

All images associated with a UIImageView object should use the same scale. If your application uses images with different scales, they may render incorrectly.

这篇关于UIImage 和 UIImageView 的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆