- (UIImage *)screenshort{
UIImage* viewImage = nil;
UIGraphicsBeginImageContextWithOptions(self.contentSize, self.opaque, 0.0);
{
CGPoint savedContentOffset = self.contentOffset;
CGRect savedFrame = self.frame;
UIView *tempView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.contentSize.width, self.contentSize.height)];
UIView *tempSuperView = self.superview;
[self removeFromSuperview];
[tempView addSubview:self];
self.contentOffset = CGPointZero;
self.frame = CGRectMake(0, 0, self.contentSize.width, self.contentSize.height);
[self.layer renderInContext: UIGraphicsGetCurrentContext()];
viewImage = UIGraphicsGetImageFromCurrentImageContext();
[self removeFromSuperview];
[tempSuperView addSubview:self];
self.contentOffset = savedContentOffset;
self.frame = savedFrame;
}
UIGraphicsEndImageContext();
return viewImage;
}
网友评论