Cropping image with Swift and put it on center position

后端 未结 14 1180
心在旅途
心在旅途 2020-12-01 00:32

In Swift programming , how do you crop an image and put it on the center afterwards?

This is what I\'ve got so far ... I\'ve successfully crop the image but I want t

14条回答
  •  忘掉有多难
    2020-12-01 01:29

    you can also use Alamofire and AlamofireImage to crop your image.

    https://github.com/Alamofire/AlamofireImage

    Installing using CocoaPods pod 'AlamofireImage'

    Usage:

    let image = UIImage(named: "unicorn")!
    let size = CGSize(width: 100.0, height: 100.0)
    // Scale image to size disregarding aspect ratio
    let scaledImage = image.af_imageScaled(to: size)
    let aspectScaledToFitImage = image.af_imageAspectScaled(toFit: size)
    
    // Scale image to fill specified size while maintaining aspect ratio
    let aspectScaledToFillImage = image.af_imageAspectScaled(toFill: size)
    

提交回复
热议问题