KingfisherWrapper
public struct KingfisherWrapper<Base>
Wrapper for Kingfisher compatible types. This type provides an extension point for connivence methods in Kingfisher.
-
Undocumented
Declaration
Swift
public let base: Base
-
Undocumented
Declaration
Swift
public init(_ base: Base)
-
Undocumented
Declaration
Swift
public static var shared: UIApplication? { get }
-
Sets an image to the image view with a
Source
.Note
This is the easiest way to use Kingfisher to boost the image setting process from a source. Since all parameters have a default value except the
source
, you can set an image from a certain URL to an image view like this:// Set image from a network source. let url = URL(string: "https://example.com/image.png")! imageView.kf.setImage(with: .network(url)) // Or set image from a data provider. let provider = LocalFileImageDataProvider(fileURL: fileURL) imageView.kf.setImage(with: .provider(provider))
For both
.network
and.provider
source, there are corresponding view extension methods. So the code above is equivalent to:imageView.kf.setImage(with: url) imageView.kf.setImage(with: provider)
Internally, this method will use
KingfisherManager
to get the source. Since this method will perform UI changes, you must call it from the main thread. BothprogressBlock
andcompletionHandler
will be also executed in the main thread.Declaration
Swift
@discardableResult public func setImage( with source: Source?, placeholder: Placeholder? = nil, options: KingfisherOptionsInfo? = nil, progressBlock: DownloadProgressBlock? = nil, completionHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
Parameters
source
The
Source
object defines data information from network or a data provider.placeholder
A placeholder to show while retrieving the image from the given
resource
.options
An options set to define image setting behaviors. See
KingfisherOptionsInfo
for more.progressBlock
Called when the image downloading progress gets updated. If the response does not contain an
expectedContentLength
, this block will not be called.completionHandler
Called when the image retrieved and set finished.
Return Value
A task represents the image downloading.
-
Sets an image to the image view with a requested resource.
Note
This is the easiest way to use Kingfisher to boost the image setting process from network. Since all parameters have a default value except the
resource
, you can set an image from a certain URL to an image view like this:let url = URL(string: "https://example.com/image.png")! imageView.kf.setImage(with: url)
Internally, this method will use
KingfisherManager
to get the requested resource, from either cache or network. Since this method will perform UI changes, you must call it from the main thread. BothprogressBlock
andcompletionHandler
will be also executed in the main thread.Declaration
Swift
@discardableResult public func setImage( with resource: Resource?, placeholder: Placeholder? = nil, options: KingfisherOptionsInfo? = nil, progressBlock: DownloadProgressBlock? = nil, completionHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
Parameters
resource
The
Resource
object contains information about the resource.placeholder
A placeholder to show while retrieving the image from the given
resource
.options
An options set to define image setting behaviors. See
KingfisherOptionsInfo
for more.progressBlock
Called when the image downloading progress gets updated. If the response does not contain an
expectedContentLength
, this block will not be called.completionHandler
Called when the image retrieved and set finished.
Return Value
A task represents the image downloading.
-
Sets an image to the image view with a data provider.
Internally, this method will use
KingfisherManager
to get the image data, from either cache or the data provider. Since this method will perform UI changes, you must call it from the main thread. BothprogressBlock
andcompletionHandler
will be also executed in the main thread.Declaration
Swift
@discardableResult public func setImage( with provider: ImageDataProvider?, placeholder: Placeholder? = nil, options: KingfisherOptionsInfo? = nil, progressBlock: DownloadProgressBlock? = nil, completionHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
Parameters
provider
The
ImageDataProvider
object contains information about the data.placeholder
A placeholder to show while retrieving the image from the given
resource
.options
An options set to define image setting behaviors. See
KingfisherOptionsInfo
for more.progressBlock
Called when the image downloading progress gets updated. If the response does not contain an
expectedContentLength
, this block will not be called.completionHandler
Called when the image retrieved and set finished.
Return Value
A task represents the image downloading.
-
Cancels the image download task of the image view if it is running. Nothing will happen if the downloading has already finished.
Declaration
Swift
public func cancelDownloadTask()
-
Undocumented
Declaration
Swift
public private(set) var taskIdentifier: Source.Identifier.Value? { get set }
-
Holds which indicator type is going to be used. Default is
.none
, means no indicator will be shown while downloading.Declaration
Swift
public var indicatorType: IndicatorType { get set }
-
Holds any type that conforms to the protocol
Indicator
. The protocolIndicator
has aview
property that will be shown when loading an image. It will benil
ifindicatorType
is.none
.Declaration
Swift
public private(set) var indicator: Indicator? { get set }
-
Represents the
Placeholder
used for this image view. APlaceholder
will be shown in the view while it is downloading an image.Declaration
Swift
public private(set) var placeholder: Placeholder? { get set }
-
Gets the image URL bound to this image view.
Declaration
Swift
@available(*, deprecated, message: "Use `taskIdentifier` instead to identify a setting task.") public private(set) var webURL: URL? { get set }
-
Sets an image to the button for a specified state with a source.
Note
Internally, this method will use
KingfisherManager
to get the requested source, from either cache or network. Since this method will perform UI changes, you must call it from the main thread. BothprogressBlock
andcompletionHandler
will be also executed in the main thread.Declaration
Swift
@discardableResult public func setImage( with source: Source?, for state: UIControl.State, placeholder: UIImage? = nil, options: KingfisherOptionsInfo? = nil, progressBlock: DownloadProgressBlock? = nil, completionHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
Parameters
source
The
Source
object contains information about the image.state
The button state to which the image should be set.
placeholder
A placeholder to show while retrieving the image from the given
resource
.options
An options set to define image setting behaviors. See
KingfisherOptionsInfo
for more.progressBlock
Called when the image downloading progress gets updated. If the response does not contain an
expectedContentLength
, this block will not be called.completionHandler
Called when the image retrieved and set finished.
Return Value
A task represents the image downloading.
-
Sets an image to the button for a specified state with a requested resource.
Note
Internally, this method will use
KingfisherManager
to get the requested resource, from either cache or network. Since this method will perform UI changes, you must call it from the main thread. BothprogressBlock
andcompletionHandler
will be also executed in the main thread.Declaration
Swift
@discardableResult public func setImage( with resource: Resource?, for state: UIControl.State, placeholder: UIImage? = nil, options: KingfisherOptionsInfo? = nil, progressBlock: DownloadProgressBlock? = nil, completionHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
Parameters
resource
The
Resource
object contains information about the resource.state
The button state to which the image should be set.
placeholder
A placeholder to show while retrieving the image from the given
resource
.options
An options set to define image setting behaviors. See
KingfisherOptionsInfo
for more.progressBlock
Called when the image downloading progress gets updated. If the response does not contain an
expectedContentLength
, this block will not be called.completionHandler
Called when the image retrieved and set finished.
Return Value
A task represents the image downloading.
-
Cancels the image download task of the button if it is running. Nothing will happen if the downloading has already finished.
Declaration
Swift
public func cancelImageDownloadTask()
-
Sets a background image to the button for a specified state with a source.
Note
Internally, this method will use
KingfisherManager
to get the requested source Since this method will perform UI changes, you must call it from the main thread. BothprogressBlock
andcompletionHandler
will be also executed in the main thread.Declaration
Swift
@discardableResult public func setBackgroundImage( with source: Source?, for state: UIControl.State, placeholder: UIImage? = nil, options: KingfisherOptionsInfo? = nil, progressBlock: DownloadProgressBlock? = nil, completionHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
Parameters
source
The
Source
object contains information about the image.state
The button state to which the image should be set.
placeholder
A placeholder to show while retrieving the image from the given
resource
.options
An options set to define image setting behaviors. See
KingfisherOptionsInfo
for more.progressBlock
Called when the image downloading progress gets updated. If the response does not contain an
expectedContentLength
, this block will not be called.completionHandler
Called when the image retrieved and set finished.
Return Value
A task represents the image downloading.
-
Sets a background image to the button for a specified state with a requested resource.
Note
Internally, this method will use
KingfisherManager
to get the requested resource, from either cache or network. Since this method will perform UI changes, you must call it from the main thread. BothprogressBlock
andcompletionHandler
will be also executed in the main thread.Declaration
Swift
@discardableResult public func setBackgroundImage( with resource: Resource?, for state: UIControl.State, placeholder: UIImage? = nil, options: KingfisherOptionsInfo? = nil, progressBlock: DownloadProgressBlock? = nil, completionHandler: ((Result<RetrieveImageResult, KingfisherError>) -> Void)? = nil) -> DownloadTask?
Parameters
resource
The
Resource
object contains information about the resource.state
The button state to which the image should be set.
placeholder
A placeholder to show while retrieving the image from the given
resource
.options
An options set to define image setting behaviors. See
KingfisherOptionsInfo
for more.progressBlock
Called when the image downloading progress gets updated. If the response does not contain an
expectedContentLength
, this block will not be called.completionHandler
Called when the image retrieved and set finished.
Return Value
A task represents the image downloading.
-
Cancels the background image download task of the button if it is running. Nothing will happen if the downloading has already finished.
Declaration
Swift
public func cancelBackgroundImageDownloadTask()
-
Undocumented
Declaration
Swift
public func taskIdentifier(for state: UIControl.State) -> Source.Identifier.Value?
-
Undocumented
Declaration
Swift
public func backgroundTaskIdentifier(for state: UIControl.State) -> Source.Identifier.Value?
-
Gets the image URL of this button for a specified state.
Declaration
Swift
@available(*, deprecated, message: "Use `taskIdentifier` instead to identify a setting task.") public func webURL(for state: UIControl.State) -> URL?
Parameters
state
The state that uses the specified image.
Return Value
Current URL for image.
-
Gets the background image URL of this button for a specified state.
Declaration
Swift
@available(*, deprecated, message: "Use `backgroundTaskIdentifier` instead to identify a setting task.") public func backgroundWebURL(for state: UIControl.State) -> URL?
Parameters
state
The state that uses the specified background image.
Return Value
Current URL for image.
-
Undocumented
Declaration
Swift
public static func image( data: Data, scale: CGFloat, preloadAllAnimationData: Bool, onlyFirstFrame: Bool) -> Image?
-
Undocumented
Declaration
Swift
public static func animated( with data: Data, scale: CGFloat = 1.0, duration: TimeInterval = 0.0, preloadAll: Bool, onlyFirstFrame: Bool = false) -> Image?
-
Undocumented
Declaration
Swift
@discardableResult public func setImage(with resource: Resource?, placeholder: Placeholder? = nil, options: KingfisherOptionsInfo? = nil, progressBlock: DownloadProgressBlock? = nil, completionHandler: CompletionHandler?) -> DownloadTask?
-
Undocumented
Declaration
Swift
@discardableResult public func setImage( with resource: Resource?, for state: UIControl.State, placeholder: UIImage? = nil, options: KingfisherOptionsInfo? = nil, progressBlock: DownloadProgressBlock? = nil, completionHandler: CompletionHandler?) -> DownloadTask?
-
Undocumented
Declaration
Swift
@discardableResult public func setBackgroundImage( with resource: Resource?, for state: UIControl.State, placeholder: UIImage? = nil, options: KingfisherOptionsInfo? = nil, progressBlock: DownloadProgressBlock? = nil, completionHandler: CompletionHandler?) -> DownloadTask?
-
Applies a
Filter
containingCIImage
transformer toself
.Note
Only CG-based images are supported. If any error happens during transforming,
self
will be returned.Declaration
Swift
public func apply(_ filter: Filter) -> Image
Parameters
filter
The filter used to transform
self
.Return Value
A transformed image by input
Filter
.
-
Normalize the image. This getter does nothing on macOS but return the image itself.
-
Returns normalized image for current
base
image. This method will try to redraw an image with orientation and scale considered.Declaration
Swift
public var normalized: Image { get }
-
Returns PNG representation of
base
image.Declaration
Swift
public func pngRepresentation() -> Data?
Return Value
PNG data of image.
-
Returns JPEG representation of
base
image.Declaration
Swift
public func jpegRepresentation(compressionQuality: CGFloat) -> Data?
Parameters
compressionQuality
The compression quality when converting image to JPEG data.
Return Value
JPEG data of image.
-
Returns GIF representation of
base
image.Declaration
Swift
public func gifRepresentation() -> Data?
Return Value
Original GIF data of image.
-
Returns a data representation for
base
image, with theformat
as the format indicator.Declaration
Swift
public func data(format: ImageFormat) -> Data?
Parameters
format
The format in which the output data should be. If
unknown
, thebase
image will be converted in the PNG representation.Return Value
The output data representing.
-
Creates an animated image from a given data and options. Currently only GIF data is supported.
Declaration
Swift
public static func animatedImage(data: Data, options: ImageCreatingOptions) -> Image?
Parameters
data
The animated image data.
options
Options to use when creating the animated image.
Return Value
An
Image
object represents the animated image. It is in form of an array of image frames with a certain duration.nil
if anything wrong when creating animated image. -
Creates an image from a given data and options.
.JPEG
,.PNG
or.GIF
is supported. For other image format, image initializer from system will be used. If no image object could be created from the givendata
,nil
will be returned.Declaration
Swift
public static func image(data: Data, options: ImageCreatingOptions) -> Image?
Parameters
data
The image data representation.
options
Options to use when creating the image.
Return Value
An
Image
object represents the image if created. If thedata
is invalid or not supported,nil
will be returned. -
Creates a downsampled image from given data to a certain size and scale.
Note
Different from image
resize
methods, downsampling will not render the original input image in pixel format. It does downsampling from the image data, so it is much more memory efficient and friendly. Choose to use downsampling as possible as you can.The input size should be smaller than the size of input image. If it is larger than the original image size, the result image will be the same size of input without downsampling.
Declaration
Swift
public static func downsampledImage(data: Data, to pointSize: CGSize, scale: CGFloat) -> Image?
Parameters
data
The image data contains a JPEG or PNG image.
pointSize
The target size in point to which the image should be downsampled.
scale
The scale of result image.
Return Value
A downsampled
Image
object following the input conditions.
-
Undocumented
Declaration
Swift
public func image(withBlendMode blendMode: CGBlendMode, alpha: CGFloat = 1.0, backgroundColor: Color? = nil) -> Image
-
Creates a round corner image from on
base
image.Note
This method only works for CG-based image. The current image scale is kept. For any non-CG-based image,
base
itself is returned.Declaration
Swift
public func image(withRoundRadius radius: CGFloat, fit size: CGSize, roundingCorners corners: RectCorner = .all, backgroundColor: Color? = nil) -> Image
Parameters
radius
The round corner radius of creating image.
size
The target size of creating image.
corners
The target corners which will be applied rounding.
backgroundColor
The background color for the output image
Return Value
An image with round corner of
self
.
-
Resizes
base
image to an image with new size.Note
This method only works for CG-based image. The current image scale is kept. For any non-CG-based image,base
itself is returned.Declaration
Swift
public func resize(to size: CGSize) -> Image
Parameters
size
The target size in point.
Return Value
An image with new size.
-
Resizes
base
image to an image of new size, respecting the given content mode.Note
This method only works for CG-based image. The current image scale is kept. For any non-CG-based image,
base
itself is returned.Declaration
Swift
public func resize(to targetSize: CGSize, for contentMode: ContentMode) -> Image
Parameters
targetSize
The target size in point.
contentMode
Content mode of output image should be.
Return Value
An image with new size.
-
Crops
base
image to a new size with a given anchor.Note
This method only works for CG-based image. The current image scale is kept. For any non-CG-based image,
base
itself is returned.Declaration
Swift
public func crop(to size: CGSize, anchorOn anchor: CGPoint) -> Image
Parameters
size
The target size.
anchor
The anchor point from which the size should be calculated.
Return Value
An image with new size.
-
Creates an image with blur effect based on
base
image.Note
This method only works for CG-based image. The current image scale is kept. For any non-CG-based image,
base
itself is returned.Declaration
Swift
public func blurred(withRadius radius: CGFloat) -> Image
Parameters
radius
The blur radius should be used when creating blur effect.
Return Value
An image with blur effect applied.
-
Creates an image from
base
image with a color overlay layer.Note
This method only works for CG-based image. The current image scale is kept. For any non-CG-based image,
base
itself is returned.Declaration
Swift
public func overlaying(with color: Color, fraction: CGFloat) -> Image
Parameters
color
The color should be use to overlay.
fraction
Fraction of input color. From 0.0 to 1.0. 0.0 means solid color, 1.0 means transparent overlay.
Return Value
An image with a color overlay applied.
-
Create an image from
self
with color control.Declaration
Swift
public func adjusted(brightness: CGFloat, contrast: CGFloat, saturation: CGFloat, inputEV: CGFloat) -> Image
Parameters
brightness
Brightness changing to image.
contrast
Contrast changing to image.
saturation
Saturation changing to image.
inputEV
InputEV changing to image.
Return Value
An image with color control applied.
-
Return an image with given scale.
Declaration
Swift
public func scaled(to scale: CGFloat) -> Image
Parameters
scale
Target scale factor the new image should have.
Return Value
The image with target scale. If the base image is already in the scale,
base
will be returned.
-
Returns the decoded image of the
base
image. It will draw the image in a plain context and return the data from it. This could improve the drawing performance when an image is just created from data but not yet displayed for the first time.Note
This method only works for CG-based image. The current image scale is kept. For any non-CG-based image or animated image,base
itself is returned.Declaration
Swift
public var decoded: Image { get }
-
Returns decoded image of the
base
image at a given scale. It will draw the image in a plain context and return the data from it. This could improve the drawing performance when an image is just created from data but not yet displayed for the first time.Note
This method only works for CG-based image. The current image scale is kept. For any non-CG-based image or animated image,
base
itself is returned.Declaration
Swift
public func decoded(scale: CGFloat) -> Image
Parameters
scale
The given scale of target image should be.
Return Value
The decoded image ready to be displayed.
-
Gets the image format corresponding to the data.
Declaration
Swift
public var imageFormat: ImageFormat { get }
-
Undocumented
Declaration
Swift
public func contains(jpeg marker: ImageFormat.JPEGMarker) -> Bool
-
Returns a size by resizing the
base
size to a target size under a given content mode.Declaration
Swift
public func resize(to size: CGSize, for contentMode: ContentMode) -> CGSize
Parameters
size
The target size to resize to.
contentMode
Content mode of the target size should be when resizing.
Return Value
The resized size under the given
ContentMode
. -
Returns a
CGRect
for which thebase
size is constrained to an inputsize
at a givenanchor
point.Declaration
Swift
public func constrainedRect(for size: CGSize, anchor: CGPoint) -> CGRect
Parameters
size
The size in which the
base
should be constrained to.anchor
An anchor point in which the size constraint should happen.
Return Value
The result
CGRect
for the constraint operation.