1

I want to take a screenshot that is 375x375 pixels wide, but I don't want it to start at (0, 0) in the top left of the screen, I want it to start at (0, 64). How can I accomplish this?

Here is my function:

func screenShotMethod() {
    let size = CGSize(width: 375, height: 375)
    UIGraphicsBeginImageContextWithOptions((size), false, 0.0)
    view.layer.render(in: UIGraphicsGetCurrentContext()!)
    let image = UIGraphicsGetImageFromCurrentImageContext()
    UIGraphicsEndImageContext()
    UIImageWriteToSavedPhotosAlbum(image!, nil, nil, nil)
}
rmaddy
  • 314,917
  • 42
  • 532
  • 579
Patrick
  • 13
  • 2
  • You can take size(375, 375+64) and crop rect(0, 64, 375, 375). [Crop Image](http://stackoverflow.com/a/7704399/6279975) – tomfriwel May 08 '17 at 03:16

1 Answers1

0

One way that you can do it is creating a UIView with the same size that you want and make its background to be clear color and then use that UIView instead of the view in your code.

You can also use the code here which is an extension for UIView and does exactly what you want to do

Community
  • 1
  • 1
manman
  • 4,743
  • 3
  • 30
  • 42