Saturday, February 07, 2009

Programmatically Taking a Screenshot in iPhone

It took me some time to find the code for this. Thought I'd share it here. The following code takes a screen capture of the currently visible portions of a UITableView but its applicable to any view.

UIGraphicsBeginImageContext(self.tableView.bounds.size);
[self.tableView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
//UIImageWriteToSavedPhotosAlbum(viewImage, nil, nil, nil);
UIGraphicsEndImageContext();

The commented out line saves the photo to a the Photos application on the iPhone.

Int size on Apple Watch (watchOS)

  Even though Apple Watch chipset is 64-bits, Int is still 32-bit. To get 64 bit behavior you have to explicitly use Int64 https:// jeffver...