Search code examples
iosxcodescreenshottabbar

problems with Screenshot size in application with tabbar


I have a simple app with a tabbar. The view size is 480 x 320. The tabbar is 49 x 320. However when i try to take a screenshot using UIgraphicsbeginimagecontext(self.view.frame.size) I get an image of 411 x 320.. My background image is 480 x 320 and shows properly in the ios simulator.

When I use UIgraphicsbeginimagecontext(480x320) I get empty space in the bottom of the screenshot..

However when the screen is captured the background image is cut by the 69 height pixels. Anyone knows why my background image displays properly in simulator but is cropped when taking a screenshot.. Or how to capture all the screenshot if I increase the imagecontext size?

Many Thanks


Solution

  • Is the status bar showing? It sounds like the status bar (20px) and the UITabBar (49px) is where the extra space is being cropped. I imagine that self.view is returning a UIViewControllers view which is smaller than the shot you want.

    If you want just the background image, try reducing the size of the screen shot, or if you want the whole screen, try targeting the apps main window, something like this

    UIGraphicsBeginImageContext(self.window.bounds.size);
    [self.window.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();