UIImage
class UIImage : NSObject, NSSecureCoding
-
Mechanica
Returns an image with a background
color,sizeandscale.Note
The size of the rectangle is beeing rounded from UIKit.Declaration
Swift
public convenience init?(color: UIColor, size: CGSize = CGSize(width: 1, height: 1), scale scaleFactor: CGFloat = 0.0)Parameters
colorThe background UIColor.
sizeThe image size (default is 1x1).
scaleFactorThe scale factor to apply; if you specify a value of 0.0, the scale factor is set to the scale factor of the device’s main screen.
-
Mechanica
Returns a new version of the image scaled to the specified size.
Note
The opaqueness is the same of the initial images.
Declaration
Swift
public func scaled(to size: CGSize, scale scaleFactor: CGFloat = 0.0) -> UIImageParameters
sizeThe size to use when scaling the new image.
Return Value
A
newscaled UIImage. -
Mechanica
Returns a new version of the image scaled to the specified size.
Declaration
Swift
public func scaled(to size: CGSize, opaque: Bool = false, scale scaleFactor: CGFloat = 0.0) -> UIImageParameters
sizeThe size to use when scaling the new image.
opaqueSpecifying
falsemeans that the image will include an alpha channel.Return Value
A
newscaled UIImage. -
Mechanica
Returns a new version of the image scaled from the center while maintaining the aspect ratio to fit within a specified size.
Declaration
Swift
public func aspectScaled(toFit size: CGSize, scale scaleFactor: CGFloat = 0.0) -> UIImageParameters
sizeThe size to use when scaling the new image.
scaleFactorThe display scale of the image renderer context (defaults to the scale of the main screen).
Return Value
A new image object.
-
Mechanica
Returns a new version of the image scaled from the center while maintaining the aspect ratio to fill a specified size. Any pixels that fall outside the specified size are clipped.
Declaration
Swift
public func aspectScaled(toFill size: CGSize, scale scaleFactor: CGFloat = 0.0) -> UIImageParameters
sizeThe size to use when scaling the new image.
scaleFactorThe display scale of the image renderer context (defaults to the scale of the main screen).
Return Value
A new
UIImageobject.
-
Mechanica
Returns a new version of the image with the corners rounded to the specified radius.
Declaration
Swift
public func rounded(withCornerRadius radius: CGFloat, divideRadiusByImageScale: Bool = false, scale scaleFactor: CGFloat = 0.0) -> UIImageParameters
radiusThe radius to use when rounding the new image.
divideRadiusByImageScaleWhether to divide the radius by the image scale. Set to
truewhen the image has the same resolution for all screen scales such as @1x, @2x and @3x (i.e. single image from web server). Set tofalsefor images loaded from an asset catalog with varying resolutions for each screen scale.falseby default.scaleFactorThe display scale of the image renderer context (defaults to the scale of the main screen).
Return Value
A new
UIImageobject. -
Mechanica
Returns a new version of the image rounded into a circle.
Declaration
Swift
public func roundedIntoCircle(scale scaleFactor: CGFloat = 0.0) -> UIImageParameters
scaleFactorThe display scale of the image renderer context (defaults to the scale of the main screen).
Return Value
A new
UIImageobject. -
Mechanica
Returns a new decoded version of the image.
It allows a bitmap representation to be decoded in the background rather than on the main thread.
Declaration
Swift
public func decoded(scale: CGFloat? = .none, allowedMaxSize: Int = 4096 * 4096) -> UIImage?Parameters
scaleThe scale factor to assume when interpreting the image data (defaults to
self.scale); the decoded image will have its size divided by this scale parameter.allowedMaxSizeThe allowed max size, if the image is too large the decoding operation will return nil.
Return Value
A new decoded
UIImageobject.
UIImage Extension Reference