UIImageView Class Reference
| Inherits from | |
| Conforms to | |
| Framework | /System/Library/Frameworks/UIKit.framework |
| Availability | Available in iOS 2.0 and later. |
| Declared in | UIImageView.h |
Overview
An image view object 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.
For information about basic view behaviors, see View Programming Guide for iOS.
State Preservation
In iOS 6 and later, if you assign a value to this view’s restorationIdentifier property, it attempts to preserve the frame of the displayed image. Specifically, the class preserves the values of the bounds, center, and transform properties of the view and the anchorPoint property of the underlying layer. During restoration, the image view restores these values so that the image appears exactly as before. For more information about how state preservation and restoration works, see iOS App Programming Guide.
Subclassing Notes
Special Considerations
The UIImageView class is optimized to draw its images to the display. UIImageView will not call the drawRect: method of a subclass. If your subclass needs custom drawing code, it is recommended you use UIView as the base class.
Tasks
Initializing a UIImageView Object
Image Data
-
imageproperty -
highlightedImageproperty
Animating Images
-
animationImagesproperty -
highlightedAnimationImagesproperty -
animationDurationproperty -
animationRepeatCountproperty -
– startAnimating -
– stopAnimating -
– isAnimating
Setting and Getting Attributes
-
userInteractionEnabledproperty -
highlightedproperty
Properties
animationDuration
The amount of time it takes to go through one cycle of the images.
Discussion
The time duration is measured in seconds. The default value of this property is equal to the number of images multiplied by 1/30th of a second. Thus, if you had 30 images, the value would be 1 second.
Availability
- Available in iOS 2.0 and later.
Declared In
UIImageView.hanimationImages
An array of UIImage objects to use for an animation.
Discussion
The array must contain UIImage objects. You may use the same image object more than once in the array. Setting this property to a value other than nil hides the image represented by the image property. The value of this property is nil by default.
Availability
- Available in iOS 2.0 and later.
See Also
-
@property image -
contentMode(UIView)
Declared In
UIImageView.hanimationRepeatCount
Specifies the number of times to repeat the animation.
Discussion
The default value is 0, which specifies to repeat the animation indefinitely.
Availability
- Available in iOS 2.0 and later.
Declared In
UIImageView.hhighlighted
A Boolean value that determines whether the image is highlighted.
Discussion
This property determines whether the regular or highlighted images are used. When highlighted is set to YES, a non-animated image will use the highlightedImage property and an animated image will use the highlightedAnimationImages. If both of those properties are set to nil or if highlighted is set to NO, it will use the image and animationImages properties.
Availability
- Available in iOS 3.0 and later.
Declared In
UIImageView.hhighlightedAnimationImages
An array of UIImage objects to use for an animation when the view is highlighted.
Discussion
The array must contain UIImage objects. You may use the same image object more than once in the array. Setting this property to a value other than nil hides the image represented by the highlightedImage property. The value of this property is nil by default.
Availability
- Available in iOS 3.0 and later.
See Also
-
@property highlightedImage -
contentMode(UIView)
Declared In
UIImageView.hhighlightedImage
The highlighted image displayed in the image view.
Discussion
The initial value of this property is the image passed into the initWithImage:highlightedImage: method or nil if you initialized the receiver using a different method.
If the highlightedAnimationImages property contains a value other than nil, the contents of this property are not used.
Availability
- Available in iOS 3.0 and later.
See Also
Declared In
UIImageView.himage
The image displayed in the image view.
Discussion
The initial value of this property is the image passed into the initWithImage: method or nil if you initialized the receiver using a different method.
If the animationImages property contains a value other than nil, the contents of this property are not used.
Setting the image property does not change the size of a UIImageView. Call sizeToFit to adjust the size of the view to match the image.
Availability
- Available in iOS 2.0 and later.
See Also
Declared In
UIImageView.huserInteractionEnabled
A Boolean value that determines whether user events are ignored and removed from the event queue.
Discussion
This property is inherited from the UIView parent class. This class changes the default value of this property to NO.
Availability
- Available in iOS 2.0 and later.
Declared In
UIImageView.hInstance Methods
initWithImage:
Returns an image view initialized with the specified image.
Parameters
- image
The initial image to display in the image view.
Return Value
An initialized image view object.
Discussion
This method adjusts the frame of the receiver to match the size of the specified image. It also disables user interactions for the image view by default.
Availability
- Available in iOS 2.0 and later.
Declared In
UIImageView.hinitWithImage:highlightedImage:
Returns an image view initialized with the specified regular and highlighted images.
Parameters
- image
The initial image to display in the image view.
- highlightedImage
The image to display if the image view is highlighted.
Return Value
An initialized image view object.
Discussion
This method adjusts the frame of the receiver to match the size of the specified image. It also disables user interactions for the image view by default.
Availability
- Available in iOS 3.0 and later.
Declared In
UIImageView.hisAnimating
Returns a Boolean value indicating whether the animation is running.
Return Value
YES if the animation is running; otherwise, NO.
Availability
- Available in iOS 2.0 and later.
Declared In
UIImageView.h© 2012 Apple Inc. All Rights Reserved. (Last updated: 2012-09-19)