UIImageView
extension UIImageView
-
Used to wrap all
See moreUIView
animation transition options alongside a duration.Declaration
Swift
public enum ImageTransition
-
The instance image downloader used to download all images. If this property is
nil
, theUIImageView
will fallback on theaf_sharedImageDownloader
for all downloads. The most common use case for needing to use a custom instance image downloader is when images are behind different basic auth credentials.Declaration
Swift
public var af_imageDownloader: ImageDownloader? { get set }
-
The shared image downloader used to download all images. By default, this is the default
ImageDownloader
instance backed with anAutoPurgingImageCache
which automatically evicts images from the cache when the memory capacity is reached or memory warning notifications occur. The shared image downloader is only used if theaf_imageDownloader
isnil
.Declaration
Swift
public class var af_sharedImageDownloader: ImageDownloader { get set }
-
af_setImage(withURL:placeholderImage:filter:progress:progressQueue:imageTransition:runImageTransitionIfCached:completion:)
Asynchronously downloads an image from the specified URL, applies the specified image filter to the downloaded image and sets it once finished while executing the image transition.
If the image is cached locally, the image is set immediately. Otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the image request is finished.
The
completion
closure is called after the image download and filtering are complete, but before the start of the image transition. Please note it is no longer the responsibility of thecompletion
closure to set the image. It will be set automatically. If you require a second notification after the image transition completes, use a.Custom
image transition with acompletion
closure. The.Custom
completion
closure is called when the image transition is finished.Declaration
Swift
public func af_setImage( withURL url: URL, placeholderImage: UIImage? = nil, filter: ImageFilter? = nil, progress: ImageDownloader.ProgressHandler? = nil, progressQueue: DispatchQueue = DispatchQueue.main, imageTransition: ImageTransition = .noTransition, runImageTransitionIfCached: Bool = false, completion: ((DataResponse<UIImage>) -> Void)? = nil)
Parameters
url
The URL used for the image request.
placeholderImage
The image to be set initially until the image request finished. If
nil
, the image view will not change its image until the image request finishes. Defaults tonil
.filter
The image filter applied to the image after the image request is finished. Defaults to
nil
.progress
The closure to be executed periodically during the lifecycle of the request. Defaults to
nil
.progressQueue
The dispatch queue to call the progress closure on. Defaults to the main queue.
imageTransition
The image transition animation applied to the image when set. Defaults to
.None
.runImageTransitionIfCached
Whether to run the image transition if the image is cached. Defaults to
false
.completion
A closure to be executed when the image request finishes. The closure has no return value and takes three arguments: the original request, the response from the server and the result containing either the image or the error that occurred. If the image was returned from the image cache, the response will be
nil
. Defaults tonil
. -
af_setImage(withURLRequest:placeholderImage:filter:progress:progressQueue:imageTransition:runImageTransitionIfCached:completion:)
Asynchronously downloads an image from the specified URL Request, applies the specified image filter to the downloaded image and sets it once finished while executing the image transition.
If the image is cached locally, the image is set immediately. Otherwise the specified placeholder image will be set immediately, and then the remote image will be set once the image request is finished.
The
completion
closure is called after the image download and filtering are complete, but before the start of the image transition. Please note it is no longer the responsibility of thecompletion
closure to set the image. It will be set automatically. If you require a second notification after the image transition completes, use a.Custom
image transition with acompletion
closure. The.Custom
completion
closure is called when the image transition is finished.Declaration
Swift
public func af_setImage( withURLRequest urlRequest: URLRequestConvertible, placeholderImage: UIImage? = nil, filter: ImageFilter? = nil, progress: ImageDownloader.ProgressHandler? = nil, progressQueue: DispatchQueue = DispatchQueue.main, imageTransition: ImageTransition = .noTransition, runImageTransitionIfCached: Bool = false, completion: ((DataResponse<UIImage>) -> Void)? = nil)
Parameters
urlRequest
The URL request.
placeholderImage
The image to be set initially until the image request finished. If
nil
, the image view will not change its image until the image request finishes. Defaults tonil
.filter
The image filter applied to the image after the image request is finished. Defaults to
nil
.progress
The closure to be executed periodically during the lifecycle of the request. Defaults to
nil
.progressQueue
The dispatch queue to call the progress closure on. Defaults to the main queue.
imageTransition
The image transition animation applied to the image when set. Defaults to
.None
.runImageTransitionIfCached
Whether to run the image transition if the image is cached. Defaults to
false
.completion
A closure to be executed when the image request finishes. The closure has no return value and takes three arguments: the original request, the response from the server and the result containing either the image or the error that occurred. If the image was returned from the image cache, the response will be
nil
. Defaults tonil
.
-
Cancels the active download request, if one exists.
Declaration
Swift
public func af_cancelImageRequest()
-
Runs the image transition on the image view with the specified image.
Declaration
Swift
public func run(_ imageTransition: ImageTransition, with image: Image)
Parameters
imageTransition
The image transition to ran on the image view.
image
The image to use for the image transition.