In iPhone application I want to generate a image of UIScrollView whose content size is near about 600*41000. If I use current graphic image context to capture the scroll view layer, then it only captures the visible part of the scroll view not the whole layer of that scroll view.
I am using the below code:
{
UIGraphicsBeginImageContext(CGSizeMake(600, 4100));
[scrollView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *img = [[UIImageView alloc]initWithFrame:CGRectMake(00, 100, 710, 4100)];
img.image = viewImage;
[anotherScrollView addSubview:img];
}
Try to generate image not from
UIScrollViewbut from its content view. When you add some views toUIScrollViewwith something likeaddSubview:they become scroll’s content ones. Of course,UIScrollViewcan have more than one content view (just as anyUIViewcan have more than one subview) and this case it will be more difficult to render its layer. But in case of only one subview (content view) you can use something like (contentViewhere is just some view, added toUIScrollViewbefore):[contentView.layer renderInContext:UIGraphicsGetCurrentContext()];or:
[[[[scrollView subviews] lastObject] layer] renderInContext:UIGraphicsGetCurrentContext()];When you want to use more than one view, it will be easier (I think) to add one more “root” view and add others as that view’s subviews: so you can also use the code above.