wantedly/ImageHelper

Name: ImageHelper

Owner: Wantedly, Inc.

Description: Convenience extension for UIImage and UIImageView in Swift

Forked from: melvitax/ImageHelper

Created: 2017-01-17 02:27:41.0

Updated: 2017-01-17 02:27:44.0

Pushed: 2017-01-17 02:31:45.0

Homepage: null

Size: 1627

Language: Swift

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

ImageHelper

Version License Platform Carthage compatible

Image Extensions for Swift 3.0

Sample Project Screenshot

Usage

To run the example project, clone or download the repo, and run.

UIImageView Extension
Image from a URL
etches an image from a URL. If caching is set, it will be cached by NSCache for future queries. The cached image is returned if available, otherise the placeholder is set. When the image is returned, the closure gets called.
 imageFromURL(url: String, placeholder: UIImage, fadeIn: Bool = true, closure: ((image: UIImage?)
UIImage Extension
Colors
reates an image from a solid color
age(color:UIColor, size:CGSize)

reates an image from a gradient color
age(gradientColors:[UIColor], size:CGSize)

pplies a gradient overlay to an image
 applyGradientColors(gradientColors: [UIColor], blendMode: CGBlendMode) -> UIImage

reates an image from a radial gradient
age(startColor: UIColor, endColor: UIColor, radialGradientCenter: CGPoint, radius:Float, size:CGSize)
Text
reates an image with a string of text
age(text: String, font: UIFont, color: UIColor, backgroundColor: UIColor, size:CGSize, offset: CGPoint)
Screenshot
reates an image from a UIView
age(fromView view: UIView)
Alpha and Padding
eturns true if the image has an alpha layer
 hasAlpha() -> Bool

eturns a copy(if needed) of the image with alpha layer
 applyAlpha() -> UIImage?

eturns a copy of the image with a transparent border of the given size added around its edges
 applyPadding(padding: CGFloat) -> UIImage?
Crop and Resize
rops an image to a new rect
 crop(bounds: CGRect) -> UIImage?

rops an image to a centered square
 cropToSquare() -> UIImage? {

esizes an image
 resize(size:CGSize, contentMode: UIImageContentMode = .ScaleToFill) -> UIImage?
Circle and Rounded Corners
ounds corners of an image
 roundCorners(cornerRadius:CGFloat) -> UIImage?

ounds corners of an image with border
 roundCorners(cornerRadius:CGFloat, border:CGFloat, color:UIColor) -> UIImage?

ounds corners to a circle
 roundCornersToCircle() -> UIImage?

ounds corners to a circle with border
 roundCornersToCircle(border border:CGFloat, color:UIColor) -> UIImage?
Border
dds a border
 applyBorder(border:CGFloat, color:UIColor) -> UIImage?
Image Effects
pplies a light blur effect to the image
 applyLightEffect() -> UIImage?
pplies a extra light blur effect to the image
 applyExtraLightEffect() -> UIImage?
pplies a dark blur effect to the image
 applyDarkEffect() -> UIImage?
pplies a color tint to an image
 applyTintEffect(tintColor: UIColor) -> UIImage?
pplies a blur to an image based on the specified radius, tint color saturation and mask image
 applyBlur(blurRadius:CGFloat, tintColor:UIColor?, saturationDeltaFactor:CGFloat, maskImage:UIImage? = nil) -> UIImage?
Screen Density
o create an image that is Retina aware, use the screen scale as a multiplier for your size. You should also use this technique for padding or borders.
width = 140 * UIScreen.mainScreen().scale
height = 140 * UIScreen.mainScreen().scale
image = UIImage(named: "myImage")?.resize(CGSize(width: width, height: height))

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.