Tuesday 4 August 2015

Convert UIView to UIImage. Taking screenshot programatically iOS.

-(UIImage *)convertViewToImage:(UIView*)view
{
    UIGraphicsBeginImageContext(view.bounds.size);//context create a canvas to draw 
    [view drawViewHierarchyInRect: view.bounds afterScreenUpdates:YES];//draws the view hierarchy into the current context
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();//Fetches UIImage from the current context
    UIGraphicsEndImageContext();// Context ends.
 
    return image;
}