UIButton

  • The instance image downloader used to download all images. If this property is nil, the UIButton will fallback on the af_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?
  • The shared image downloader used to download all images. By default, this is the default ImageDownloader instance backed with an AutoPurgingImageCache 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 the af_imageDownloader is nil.

    Declaration

    Swift

    public class var af_sharedImageDownloader: ImageDownloader
  • Asynchronously downloads an image from the specified URL and sets it once the request is finished.

    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.

    Declaration

    Swift

    public func af_setImage(
        for state: UIControlState,
        url: URL,
        placeholderImage: UIImage? = nil,
        filter: ImageFilter? = nil,
        progress: ImageDownloader.ProgressHandler? = nil,
        progressQueue: DispatchQueue = DispatchQueue.main,
        completion: ((DataResponse<UIImage>) -> Void)? = nil)

    Parameters

    state

    The control state of the button to set the image on.

    url

    The URL used for your image request.

    placeholderImage

    The image to be set initially until the image request finished. If nil, the image will not change its image until the image request finishes. Defaults to nil.

    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.

    completion

    A closure to be executed when the image request finishes. The closure takes a single response value containing either the image or the error that occurred. If the image was returned from the image cache, the response will be nil. Defaults to nil.

  • Asynchronously downloads an image from the specified URL request and sets it once the request is finished.

    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.

    Declaration

    Swift

    public func af_setImage(
        for state: UIControlState,
        urlRequest: URLRequestConvertible,
        placeholderImage: UIImage? = nil,
        filter: ImageFilter? = nil,
        progress: ImageDownloader.ProgressHandler? = nil,
        progressQueue: DispatchQueue = DispatchQueue.main,
        completion: ((DataResponse<UIImage>) -> Void)? = nil)

    Parameters

    state

    The control state of the button to set the image on.

    urlRequest

    The URL request.

    placeholderImage

    The image to be set initially until the image request finished. If nil, the image will not change its image until the image request finishes. Defaults to nil.

    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.

    completion

    A closure to be executed when the image request finishes. The closure takes a single response value containing either the image or the error that occurred. If the image was returned from the image cache, the response will be nil. Defaults to nil.

  • Cancels the active download request for the image, if one exists.

    Declaration

    Swift

    public func af_cancelImageRequest(for state: UIControlState)
  • Asynchronously downloads an image from the specified URL and sets it once the request is finished.

    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.

    Declaration

    Swift

    public func af_setBackgroundImage(
        for state: UIControlState,
        url: URL,
        placeholderImage: UIImage? = nil,
        filter: ImageFilter? = nil,
        progress: ImageDownloader.ProgressHandler? = nil,
        progressQueue: DispatchQueue = DispatchQueue.main,
        completion: ((DataResponse<UIImage>) -> Void)? = nil)

    Parameters

    state

    The control state of the button to set the image on.

    url

    The URL used for the image request.

    placeholderImage

    The image to be set initially until the image request finished. If nil, the background image will not change its image until the image request finishes. Defaults to nil.

    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.

    completion

    A closure to be executed when the image request finishes. The closure takes a single response value containing either the image or the error that occurred. If the image was returned from the image cache, the response will be nil. Defaults to nil.

  • Asynchronously downloads an image from the specified URL request and sets it once the request is finished.

    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.

    Declaration

    Swift

    public func af_setBackgroundImage(
        for state: UIControlState,
        urlRequest: URLRequestConvertible,
        placeholderImage: UIImage? = nil,
        filter: ImageFilter? = nil,
        progress: ImageDownloader.ProgressHandler? = nil,
        progressQueue: DispatchQueue = DispatchQueue.main,
        completion: ((DataResponse<UIImage>) -> Void)? = nil)

    Parameters

    state

    The control state of the button to set the image on.

    urlRequest

    The URL request.

    placeholderImage

    The image to be set initially until the image request finished. If nil, the background image will not change its image until the image request finishes. Defaults to nil.

    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.

    completion

    A closure to be executed when the image request finishes. The closure takes a single response value containing either the image or the error that occurred. If the image was returned from the image cache, the response will be nil. Defaults to nil.

  • Cancels the active download request for the background image, if one exists.

    Declaration

    Swift

    public func af_cancelBackgroundImageRequest(for state: UIControlState)