Skip to content

Instantly share code, notes, and snippets.

@katiesmillie
Created December 5, 2016 15:38
Show Gist options
  • Save katiesmillie/833c67cd9be8d1603eed9ae9c071e087 to your computer and use it in GitHub Desktop.
Save katiesmillie/833c67cd9be8d1603eed9ae9c071e087 to your computer and use it in GitHub Desktop.
UIImage Extension Swift 3 - Change Alpha & Scale / Change Size
extension UIImage {
func alpha(value: CGFloat) -> UIImage {
let format = UIGraphicsImageRendererFormat()
return UIGraphicsImageRenderer(size: size, format: format).image { _ in
draw(at: CGPoint.zero, blendMode: .normal, alpha: value)
}
}
func scale(newSize: CGSize) -> UIImage {
let format = UIGraphicsImageRendererFormat()
return UIGraphicsImageRenderer(size: newSize, format: format).image { _ in
draw(at: CGPoint.zero)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment