UIImage
extension UIImage
-
Applies a lightening (blur) effect to the image
Declaration
Swift
public func applyLightEffect() -> UIImage?
Return Value
The lightened image, or nil if error.
-
Applies an extra lightening (blur) effect to the image
Declaration
Swift
public func applyExtraLightEffect() -> UIImage?
Return Value
The extra lightened image, or nil if error.
-
Applies a darkening (blur) effect to the image.
Declaration
Swift
public func applyDarkEffect() -> UIImage?
Return Value
The darkened image, or nil if error.
-
Tints the image with the given color.
Declaration
Swift
public func applyTintEffect(withColor tintColor: UIColor) -> UIImage?
Parameters
tintColor
The tint color
Return Value
The tinted image, or nil if error.
-
Core function to create a new image with the given blur.
Declaration
Swift
public func applyBlur(withRadius blurRadius: CGFloat, tintColor: UIColor?, saturationDeltaFactor: CGFloat, maskImage: UIImage? = nil) -> UIImage?
Parameters
blurRadius
The blur radius
tintColor
The color to tint the image; optional.
saturationDeltaFactor
The delta by which to change the image saturation
maskImage
An optional image mask.
Return Value
The adjusted image, or nil if error.
-
Returns a copy of self, tinted by the given color.
Declaration
Swift
public func tinted(_ tintColor: UIColor) -> UIImage
Parameters
tintColor
The UIColor to tint by.
Return Value
A copy of self, tinted by the tintColor.
-
Returns a copy of self, scaled by a specified scale factor (with an optional image orientation).
Example:
let image = UIImage(named: <image_name>) // image size = (width: 200, height: 100) image?.resized(width: 50, height: 50) // image size = (width: 50, height: 50) image?.resized(width: 50, height: 50, maintainAspectRatio: true) // image size = (width: 50, height: 25)
Declaration
Swift
public func resized(width: CGFloat, height: CGFloat, maintainAspectRatio: Bool = false) -> UIImage?
Parameters
width
The width to which to resize the image.
height
The height to which to resize the image.
maintainAspectRatio
A Boolean flag indicating whether or not to maintain the image’s aspect ratio when resizing (optional, defaults to
false
).Return Value
A copy of self, resized to a specified width and heigh (with an option to maintain the original aspect ratio).
-
Returns a copy of self, scaled by a specified scale factor (with an optional image orientation).
Example:
let image = UIImage(named: <image_name>) // image size = (width: 200, height: 100) image?.scaled(by: 0.25) // image size = (width: 50, height: 25) image?.scaled(by: 2) // image size = (width: 400, height: 200)
Declaration
Swift
public func scaled(by scaleFactor: CGFloat, withOrientation orientation: UIImage.Orientation? = nil) -> UIImage?
Parameters
scaleFactor
The factor at which to scale this image.
orientiation
The orientation to use for the scaled image (optional, defaults to the image’s
imageOrientation
property).Return Value
A copy of self, scaled by the scaleFactor (with an optional image orientation).
-
Returns an optional image using the
drawingCommands
Example:
let image = UIImage(size: CGSize(width: 12, height: 24)) { let path = UIBezierPath() path.move(to: ...) path.addLine(to: ...) path.addLine(to: ...) path.lineWidth = 2 UIColor.white.setStroke() path.stroke() }
Declaration
Swift
public convenience init?(size: CGSize, drawingCommands commands: () -> Void)
Parameters
size
The image size.
drawingCommands
A closure describing the path, fill/stroke color, etc.
Return Value
An optional image based on
drawingCommands
. -
Returns an optional image using the specified color
Declaration
Swift
public convenience init?(color: UIColor)
Parameters
color
The color of the image.
Return Value
An optional image based on
color
.