Skip to content

Instantly share code, notes, and snippets.

@mohsinbmwm3
Created January 18, 2021 14:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mohsinbmwm3/b5457959b4b370eaf20571cc9ae8272e to your computer and use it in GitHub Desktop.
Save mohsinbmwm3/b5457959b4b370eaf20571cc9ae8272e to your computer and use it in GitHub Desktop.
Some UIImage extensions
import UIKit
extension UIImage {
func resize(height: CGFloat, width: CGFloat) -> UIImage {
UIGraphicsBeginImageContext(CGSize(width: width, height: height))
draw(in: CGRect(x: 0, y: 0, width: width, height: height))
let resizedImage = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return resizedImage!
}
static func defaultProfilePicture() -> UIImage {
// This can be useful when user dont have a profile picture.
return UIImage(imageLiteralResourceName: "YourDefaultProfilePictureImageAssetName")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment