UIButton(WebCache)

@interface UIButton (WebCache)

Integrates SDWebImage async downloading and caching of remote images with UIButton.

Image

  • Get the current image URL.

    Declaration

    Objective-C

    @property (readonly, strong, nonatomic, nullable) NSURL *sd_currentImageURL;

    Swift

    var sd_currentImageURL: URL? { get }
  • Get the image URL for a control state.

    Declaration

    Objective-C

    - (nullable NSURL *)sd_imageURLForState:(UIControlState)state;

    Swift

    func sd_imageURL(for state: UIControl.State) -> URL?

    Parameters

    state

    Which state you want to know the URL for. The values are described in UIControlState.

  • Set the button image with an url.

    The download is asynchronous and cached.

    Declaration

    Objective-C

    - (void)sd_setImageWithURL:(nullable NSURL *)url forState:(UIControlState)state;

    Swift

    func __sd_setImage(with url: URL?, for state: UIControl.State)

    Parameters

    url

    The url for the image.

    state

    The state that uses the specified title. The values are described in UIControlState.

  • Set the button image with an url and a placeholder.

    The download is asynchronous and cached.

    See

    sd_setImageWithURL:placeholderImage:options:

    Declaration

    Objective-C

    - (void)sd_setImageWithURL:(nullable NSURL *)url
                      forState:(UIControlState)state
              placeholderImage:(nullable UIImage *)placeholder;

    Swift

    func __sd_setImage(with url: URL?, for state: UIControl.State, placeholderImage placeholder: UIImage?)

    Parameters

    url

    The url for the image.

    state

    The state that uses the specified title. The values are described in UIControlState.

    placeholder

    The image to be set initially, until the image request finishes.

  • Set the button image with an url, placeholder and custom options.

    The download is asynchronous and cached.

    Declaration

    Objective-C

    - (void)sd_setImageWithURL:(nullable NSURL *)url
                      forState:(UIControlState)state
              placeholderImage:(nullable UIImage *)placeholder
                       options:(SDWebImageOptions)options;

    Swift

    func __sd_setImage(with url: URL?, for state: UIControl.State, placeholderImage placeholder: UIImage?, options: SDWebImageOptions = [])

    Parameters

    url

    The url for the image.

    state

    The state that uses the specified title. The values are described in UIControlState.

    placeholder

    The image to be set initially, until the image request finishes.

    options

    The options to use when downloading the image. - see: SDWebImageOptions for the possible values.

  • Set the button image with an url, placeholder, custom options and context.

    The download is asynchronous and cached.

    Declaration

    Objective-C

    - (void)sd_setImageWithURL:(nullable NSURL *)url
                      forState:(UIControlState)state
              placeholderImage:(nullable UIImage *)placeholder
                       options:(SDWebImageOptions)options
                       context:(nullable SDWebImageContext *)context;

    Swift

    func sd_setImage(with url: URL?, for state: UIControl.State, placeholderImage placeholder: UIImage?, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]?)

    Parameters

    url

    The url for the image.

    state

    The state that uses the specified title. The values are described in UIControlState.

    placeholder

    The image to be set initially, until the image request finishes.

    options

    The options to use when downloading the image. - see: SDWebImageOptions for the possible values.

    context

    A context contains different options to perform specify changes or processes, see SDWebImageContextOption. This hold the extra objects which options enum can not hold.

  • Set the button image with an url.

    The download is asynchronous and cached.

    Declaration

    Objective-C

    - (void)sd_setImageWithURL:(nullable NSURL *)url
                      forState:(UIControlState)state
                     completed:(nullable SDExternalCompletionBlock)completedBlock;

    Swift

    func sd_setImage(with url: URL?, for state: UIControl.State, completed completedBlock: SDExternalCompletionBlock? = nil)

    Parameters

    url

    The url for the image.

    state

    The state that uses the specified title. The values are described in UIControlState.

    completedBlock

    A block called when operation has been completed. This block has no return value and takes the requested UIImage as first parameter. In case of error the image parameter is nil and the second parameter may contain an NSError. The third parameter is a Boolean indicating if the image was retrieved from the local cache or from the network. The fourth parameter is the original image url.

  • Set the button image with an url, placeholder.

    The download is asynchronous and cached.

    Declaration

    Objective-C

    - (void)sd_setImageWithURL:(nullable NSURL *)url
                      forState:(UIControlState)state
              placeholderImage:(nullable UIImage *)placeholder
                     completed:(nullable SDExternalCompletionBlock)completedBlock;

    Swift

    func __sd_setImage(with url: URL?, for state: UIControl.State, placeholderImage placeholder: UIImage?, completed completedBlock: SDExternalCompletionBlock? = nil)

    Parameters

    url

    The url for the image.

    state

    The state that uses the specified title. The values are described in UIControlState.

    placeholder

    The image to be set initially, until the image request finishes.

    completedBlock

    A block called when operation has been completed. This block has no return value and takes the requested UIImage as first parameter. In case of error the image parameter is nil and the second parameter may contain an NSError. The third parameter is a Boolean indicating if the image was retrieved from the local cache or from the network. The fourth parameter is the original image url.

  • Set the button image with an url, placeholder and custom options.

    The download is asynchronous and cached.

    Declaration

    Objective-C

    - (void)sd_setImageWithURL:(nullable NSURL *)url
                      forState:(UIControlState)state
              placeholderImage:(nullable UIImage *)placeholder
                       options:(SDWebImageOptions)options
                     completed:(nullable SDExternalCompletionBlock)completedBlock;

    Swift

    func sd_setImage(with url: URL?, for state: UIControl.State, placeholderImage placeholder: UIImage?, options: SDWebImageOptions = [], completed completedBlock: SDExternalCompletionBlock? = nil)

    Parameters

    url

    The url for the image.

    state

    The state that uses the specified title. The values are described in UIControlState.

    placeholder

    The image to be set initially, until the image request finishes.

    options

    The options to use when downloading the image. - see: SDWebImageOptions for the possible values.

    completedBlock

    A block called when operation has been completed. This block has no return value and takes the requested UIImage as first parameter. In case of error the image parameter is nil and the second parameter may contain an NSError. The third parameter is a Boolean indicating if the image was retrieved from the local cache or from the network. The fourth parameter is the original image url.

  • Set the button image with an url, placeholder and custom options.

    The download is asynchronous and cached.

    Declaration

    Objective-C

    - (void)sd_setImageWithURL:(nullable NSURL *)url
                      forState:(UIControlState)state
              placeholderImage:(nullable UIImage *)placeholder
                       options:(SDWebImageOptions)options
                      progress:(nullable SDImageLoaderProgressBlock)progressBlock
                     completed:(nullable SDExternalCompletionBlock)completedBlock;

    Swift

    func sd_setImage(with url: URL?, for state: UIControl.State, placeholderImage placeholder: UIImage?, options: SDWebImageOptions = [], progress progressBlock: SDImageLoaderProgressBlock?, completed completedBlock: SDExternalCompletionBlock? = nil)

    Parameters

    url

    The url for the image.

    state

    The state that uses the specified title. The values are described in UIControlState.

    placeholder

    The image to be set initially, until the image request finishes.

    options

    The options to use when downloading the image. - see: SDWebImageOptions for the possible values.

    progressBlock

    A block called while image is downloading - note: the progress block is executed on a background queue

    completedBlock

    A block called when operation has been completed. This block has no return value and takes the requested UIImage as first parameter. In case of error the image parameter is nil and the second parameter may contain an NSError. The third parameter is a Boolean indicating if the image was retrieved from the local cache or from the network. The fourth parameter is the original image url.

  • Set the button image with an url, placeholder, custom options and context.

    The download is asynchronous and cached.

    Declaration

    Objective-C

    - (void)sd_setImageWithURL:(nullable NSURL *)url
                      forState:(UIControlState)state
              placeholderImage:(nullable UIImage *)placeholder
                       options:(SDWebImageOptions)options
                       context:(nullable SDWebImageContext *)context
                      progress:(nullable SDImageLoaderProgressBlock)progressBlock
                     completed:(nullable SDExternalCompletionBlock)completedBlock;

    Swift

    func sd_setImage(with url: URL?, for state: UIControl.State, placeholderImage placeholder: UIImage?, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]?, progress progressBlock: SDImageLoaderProgressBlock?, completed completedBlock: SDExternalCompletionBlock? = nil)

    Parameters

    url

    The url for the image.

    state

    The state that uses the specified title. The values are described in UIControlState.

    placeholder

    The image to be set initially, until the image request finishes.

    options

    The options to use when downloading the image. - see: SDWebImageOptions for the possible values.

    context

    A context contains different options to perform specify changes or processes, see SDWebImageContextOption. This hold the extra objects which options enum can not hold.

    progressBlock

    A block called while image is downloading - note: the progress block is executed on a background queue

    completedBlock

    A block called when operation has been completed. This block has no return value and takes the requested UIImage as first parameter. In case of error the image parameter is nil and the second parameter may contain an NSError. The third parameter is a Boolean indicating if the image was retrieved from the local cache or from the network. The fourth parameter is the original image url.

Background Image

  • Get the current background image URL.

    Declaration

    Objective-C

    @property (readonly, strong, nonatomic, nullable) NSURL *sd_currentBackgroundImageURL;

    Swift

    var sd_currentBackgroundImageURL: URL? { get }
  • Get the background image URL for a control state.

    Declaration

    Objective-C

    - (nullable NSURL *)sd_backgroundImageURLForState:(UIControlState)state;

    Swift

    func sd_backgroundImageURL(for state: UIControl.State) -> URL?

    Parameters

    state

    Which state you want to know the URL for. The values are described in UIControlState.

  • Set the button backgroundImage with an url.

    The download is asynchronous and cached.

    Declaration

    Objective-C

    - (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
                                forState:(UIControlState)state;

    Swift

    func __sd_setBackgroundImage(with url: URL?, for state: UIControl.State)

    Parameters

    url

    The url for the image.

    state

    The state that uses the specified title. The values are described in UIControlState.

  • Set the button backgroundImage with an url and a placeholder.

    The download is asynchronous and cached.

    See

    sd_setImageWithURL:placeholderImage:options:

    Declaration

    Objective-C

    - (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
                                forState:(UIControlState)state
                        placeholderImage:(nullable UIImage *)placeholder;

    Swift

    func __sd_setBackgroundImage(with url: URL?, for state: UIControl.State, placeholderImage placeholder: UIImage?)

    Parameters

    url

    The url for the image.

    state

    The state that uses the specified title. The values are described in UIControlState.

    placeholder

    The image to be set initially, until the image request finishes.

  • Set the button backgroundImage with an url, placeholder and custom options.

    The download is asynchronous and cached.

    Declaration

    Objective-C

    - (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
                                forState:(UIControlState)state
                        placeholderImage:(nullable UIImage *)placeholder
                                 options:(SDWebImageOptions)options;

    Swift

    func __sd_setBackgroundImage(with url: URL?, for state: UIControl.State, placeholderImage placeholder: UIImage?, options: SDWebImageOptions = [])

    Parameters

    url

    The url for the image.

    state

    The state that uses the specified title. The values are described in UIControlState.

    placeholder

    The image to be set initially, until the image request finishes.

    options

    The options to use when downloading the image. - see: SDWebImageOptions for the possible values.

  • Set the button backgroundImage with an url, placeholder, custom options and context.

    The download is asynchronous and cached.

    Declaration

    Objective-C

    - (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
                                forState:(UIControlState)state
                        placeholderImage:(nullable UIImage *)placeholder
                                 options:(SDWebImageOptions)options
                                 context:(nullable SDWebImageContext *)context;

    Swift

    func sd_setBackgroundImage(with url: URL?, for state: UIControl.State, placeholderImage placeholder: UIImage?, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]?)

    Parameters

    url

    The url for the image.

    state

    The state that uses the specified title. The values are described in UIControlState.

    placeholder

    The image to be set initially, until the image request finishes.

    options

    The options to use when downloading the image. - see: SDWebImageOptions for the possible values.

    context

    A context contains different options to perform specify changes or processes, see SDWebImageContextOption. This hold the extra objects which options enum can not hold.

  • Set the button backgroundImage with an url.

    The download is asynchronous and cached.

    Declaration

    Objective-C

    - (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
                                forState:(UIControlState)state
                               completed:(nullable SDExternalCompletionBlock)
                                             completedBlock;

    Swift

    func sd_setBackgroundImage(with url: URL?, for state: UIControl.State, completed completedBlock: SDExternalCompletionBlock? = nil)

    Parameters

    url

    The url for the image.

    state

    The state that uses the specified title. The values are described in UIControlState.

    completedBlock

    A block called when operation has been completed. This block has no return value and takes the requested UIImage as first parameter. In case of error the image parameter is nil and the second parameter may contain an NSError. The third parameter is a Boolean indicating if the image was retrieved from the local cache or from the network. The fourth parameter is the original image url.

  • Set the button backgroundImage with an url, placeholder.

    The download is asynchronous and cached.

    Declaration

    Objective-C

    - (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
                                forState:(UIControlState)state
                        placeholderImage:(nullable UIImage *)placeholder
                               completed:(nullable SDExternalCompletionBlock)
                                             completedBlock;

    Swift

    func __sd_setBackgroundImage(with url: URL?, for state: UIControl.State, placeholderImage placeholder: UIImage?, completed completedBlock: SDExternalCompletionBlock? = nil)

    Parameters

    url

    The url for the image.

    state

    The state that uses the specified title. The values are described in UIControlState.

    placeholder

    The image to be set initially, until the image request finishes.

    completedBlock

    A block called when operation has been completed. This block has no return value and takes the requested UIImage as first parameter. In case of error the image parameter is nil and the second parameter may contain an NSError. The third parameter is a Boolean indicating if the image was retrieved from the local cache or from the network. The fourth parameter is the original image url.

  • Set the button backgroundImage with an url, placeholder and custom options.

    The download is asynchronous and cached.

    Declaration

    Objective-C

    - (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
                                forState:(UIControlState)state
                        placeholderImage:(nullable UIImage *)placeholder
                                 options:(SDWebImageOptions)options
                               completed:(nullable SDExternalCompletionBlock)
                                             completedBlock;

    Swift

    func sd_setBackgroundImage(with url: URL?, for state: UIControl.State, placeholderImage placeholder: UIImage?, options: SDWebImageOptions = [], completed completedBlock: SDExternalCompletionBlock? = nil)

    Parameters

    url

    The url for the image.

    placeholder

    The image to be set initially, until the image request finishes.

    options

    The options to use when downloading the image. - see: SDWebImageOptions for the possible values.

    completedBlock

    A block called when operation has been completed. This block has no return value and takes the requested UIImage as first parameter. In case of error the image parameter is nil and the second parameter may contain an NSError. The third parameter is a Boolean indicating if the image was retrieved from the local cache or from the network. The fourth parameter is the original image url.

  • Set the button backgroundImage with an url, placeholder and custom options.

    The download is asynchronous and cached.

    Declaration

    Objective-C

    - (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
                                forState:(UIControlState)state
                        placeholderImage:(nullable UIImage *)placeholder
                                 options:(SDWebImageOptions)options
                                progress:(nullable SDImageLoaderProgressBlock)
                                             progressBlock
                               completed:(nullable SDExternalCompletionBlock)
                                             completedBlock;

    Swift

    func sd_setBackgroundImage(with url: URL?, for state: UIControl.State, placeholderImage placeholder: UIImage?, options: SDWebImageOptions = [], progress progressBlock: SDImageLoaderProgressBlock?, completed completedBlock: SDExternalCompletionBlock? = nil)

    Parameters

    url

    The url for the image.

    placeholder

    The image to be set initially, until the image request finishes.

    options

    The options to use when downloading the image. - see: SDWebImageOptions for the possible values.

    progressBlock

    A block called while image is downloading - note: the progress block is executed on a background queue

    completedBlock

    A block called when operation has been completed. This block has no return value and takes the requested UIImage as first parameter. In case of error the image parameter is nil and the second parameter may contain an NSError. The third parameter is a Boolean indicating if the image was retrieved from the local cache or from the network. The fourth parameter is the original image url.

  • Set the button backgroundImage with an url, placeholder, custom options and context.

    The download is asynchronous and cached.

    Declaration

    Objective-C

    - (void)sd_setBackgroundImageWithURL:(nullable NSURL *)url
                                forState:(UIControlState)state
                        placeholderImage:(nullable UIImage *)placeholder
                                 options:(SDWebImageOptions)options
                                 context:(nullable SDWebImageContext *)context
                                progress:(nullable SDImageLoaderProgressBlock)
                                             progressBlock
                               completed:(nullable SDExternalCompletionBlock)
                                             completedBlock;

    Swift

    func sd_setBackgroundImage(with url: URL?, for state: UIControl.State, placeholderImage placeholder: UIImage?, options: SDWebImageOptions = [], context: [SDWebImageContextOption : Any]?, progress progressBlock: SDImageLoaderProgressBlock?, completed completedBlock: SDExternalCompletionBlock? = nil)

    Parameters

    url

    The url for the image.

    placeholder

    The image to be set initially, until the image request finishes.

    options

    The options to use when downloading the image. - see: SDWebImageOptions for the possible values.

    context

    A context contains different options to perform specify changes or processes, see SDWebImageContextOption. This hold the extra objects which options enum can not hold.

    progressBlock

    A block called while image is downloading - note: the progress block is executed on a background queue

    completedBlock

    A block called when operation has been completed. This block has no return value and takes the requested UIImage as first parameter. In case of error the image parameter is nil and the second parameter may contain an NSError. The third parameter is a Boolean indicating if the image was retrieved from the local cache or from the network. The fourth parameter is the original image url.

Cancel

  • Cancel the current image download

    Declaration

    Objective-C

    - (void)sd_cancelImageLoadForState:(UIControlState)state;

    Swift

    func sd_cancelImageLoad(for state: UIControl.State)
  • Cancel the current backgroundImage download

    Declaration

    Objective-C

    - (void)sd_cancelBackgroundImageLoadForState:(UIControlState)state;

    Swift

    func sd_cancelBackgroundImageLoad(for state: UIControl.State)