Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If I understand what you're asking correctly (which is a big if), this should do what you want:</p> <pre><code>- (UIImage *)imageWithView:(UIView *)smallerView container:(UIView *)biggerView { // Create the image context the size you want it. The scale determines if // it's a "retina" image or not. Use 0 so it does the right thing on the // right devices. UIGraphicsBeginImageContextWithOptions(biggerView.bounds.size, NO, 0); CGContextRef c = UIGraphicsGetCurrentContext(); // When you call [view renderInContext:], it renders it as if the top left // of the context you're rendering is the view's bounds.origin (usually // CGPointZero, but it can be different for views like UIScrollView. To // get around that, we have to figure out what the "top left" we want is. // First we find out how far our view's top left corner is offset from // the "big" view's top left corner. If we just used smallerView.frame.origin // without transforming it, it would be relative to the container view, which // isn't what we want. CGPoint topLeft = [biggerView convertPoint:smallerView.frame.origin fromView:smallerView.superview]; // This offsets all subsequent drawing operations by the amount we // calculated. CGContextTranslateCTM(c, topLeft.x, topLeft.y); // Now we render the view at the right location. [smallerView.layer renderInContext:c]; // Normal stuff UIImage *image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } </code></pre> <p>Invoke that with <code>imageWithView:(UIView *)smallerImageView container:backgroundImageView</code> and it should do what you want.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload