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
tintColorThe 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
blurRadiusThe blur radius
tintColorThe color to tint the image; optional.
saturationDeltaFactorThe delta by which to change the image saturation
maskImageAn 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) -> UIImageParameters
tintColorThe 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
widthThe width to which to resize the image.
heightThe height to which to resize the image.
maintainAspectRatioA 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
scaleFactorThe factor at which to scale this image.
orientiationThe orientation to use for the scaled image (optional, defaults to the image’s
imageOrientationproperty).Return Value
A copy of self, scaled by the scaleFactor (with an optional image orientation).
-
Returns an optional image using the
drawingCommandsExample:
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
sizeThe image size.
drawingCommandsA 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
colorThe color of the image.
Return Value
An optional image based on
color.
View on GitHub
Install in Dash
UIImage Extension Reference