Cropping image with Swift and put it on center position

后端 未结 14 1176
心在旅途
心在旅途 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条回答
  •  猫巷女王i
    2020-12-01 01:12

    Or make UImage extension

    extension UIImage {
        func cropped(boundingBox: CGRect) -> UIImage? {
            guard let cgImage = self.cgImage?.cropping(to: boundingBox) else {
                return nil
            }
    
            return UIImage(cgImage: cgImage)
        }
    }
    

提交回复
热议问题