毎回検索したりしてたのでメモとして。ちょっと調べたら出てくるんだけど。
AppleのQ&Aが検索にヒットした。
- (UIImage *)snapshot:(UIView *)view { UIGraphicsBeginImageContextWithOptions(view.bounds.size, YES, 0); [view drawViewHierarchyInRect:view.bounds afterScreenUpdates:YES]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
return image;
}
とりあえず、これでViewのsnapshotは撮れる。僕はちょっと加工してUIViewのカテゴリとして使ったりしてる。
- (UIImage *)snapshot { UIGraphicsBeginImageContextWithOptions(self.bounds.size, YES, 0); [self drawViewHierarchyInRect:self.bounds afterScreenUpdates:YES]; UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext();
return image;
}
もっといい方法もありそうだけどとりあえず。iOS7から。iOS8全然調べてないけどもっと良いメソッド出てきそうだ。