objective-c - UIImage 和 UIImageView 的区别

标签 objective-c ios cocoa-touch uiimageview uiimage

UIImageUIImageView 有什么区别?有人可以举例说明吗?

最佳答案

例子:

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

UIImage Overview :

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.

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.

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.

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 Overview :

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.

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.

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.

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

关于objective-c - UIImage 和 UIImageView 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8070805/

相关文章:

javascript - 获取字符串的值类型(JSContext evaluateScript)

ios - 无法在 Swift 中的 TableView 的另一个 View Controller 中显示值

ios - 在 TableView 末尾显示导航栏

ios - 短网址的NSData无法使UIImage

iphone - iOS/Objective-C : SHA-1 and Base64

ios - 将 NstaggedpointerString 转换为 int

iphone - 从 Objective-C 使用 Url 调用谷歌地图

ios - 我可以合并 RAC 信号但仍然单独获取每个错误吗?

iphone - 我可以用 Objective-C 以外的任何语言编写 iPhone 应用程序吗?

ios - 等到多个网络请求都执行完毕——包括它们的完成 block