Search code examples
iosswiftscreenshotuigraphicscontext

Swift: Screenshot without Tab Bar


I know it's fairly easy to take a screenshot of the entire screen, with or without the navigation and status bars, using a UIGraphicsImageContext but is there a way to take one (or crop one) so that the navigation bar is visible, but the status bar and tab bar are not visible?

I've restated this question so it's more clear and added a bounty here.


Solution

  • You could set tabbar.hidden = true

    Cropping is easy as well, after taking screenshot:

    let cropRect = CGRectMake(posX, posY, width, height) // depends how you want to crop it
    
    let imageRef = CGImageCreateWithImageInRect(yourScreenshot.CGImage, cropRect)
    let image: UIImage = UIImage(CGImage: imageRef)!