Swift4.0で動作確認済みです
UIimageのextensionを作る
extension UIImage {
func ResizeUIImage(width : CGFloat, height : CGFloat)-> UIImage!{
// 引数の画像の大きさのコンテキスト作成
UIGraphicsBeginImageContext(CGSize(width: width, height: height))
// コンテキストに画像を描く
self.draw(in: CGRect(x: 0, y: 0, width: width, height: height))
// コンテキストからUIImageを作成
let newImage = UIGraphicsGetImageFromCurrentImageContext()
// コンテキストを閉じる
UIGraphicsEndImageContext()
return newImage
}
}
使用方法
// リサイズする
let resizeImage: UIImage = image.ResizeUIImage(width: 100, height: 100)