Note that there are some explanatory texts on larger screens.

plurals
  1. POCopying the drawn contents of one UIView to another
    primarykey
    data
    text
    <p>I'd like to take a UITextView and allow the user to enter text into it and then trigger a copy of the contents onto a quartz bitmap context. Does anyone know how I can perform this copy action? Should I override the drawRect method and call [super drawRect] and <em>then</em> take the resulting context and copy it? If so, does anyone have any reference to sample code to copy from one context to another?</p> <p>Update: from reading the link in the answer below, I put together this much to attempt to copy my UIView contents into a bitmap context, but something is still not right. I get my contents mirrored across the X axis (i.e. upside down). I tried using CGContextScaleCTM() but that seems to have no effect.</p> <p>I've verified that the created UIImage from the first four lines do properly create a UIImage that isn't strangely rotated/flipped, so there is something I'm doing wrong with the later calls.</p> <pre><code> // copy contents to bitmap context UIGraphicsBeginImageContext(mTextView.bounds.size); [mTextView.layer renderInContext:UIGraphicsGetCurrentContext()]; UIImage* image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); [self setNeedsDisplay]; // render the created image to the bitmap context CGImageRef cgImage = [image CGImage]; CGContextScaleCTM(mContext, 1.0, -1.0); // doesn't seem to change result CGContextDrawImage(mContext, CGRectMake( mTextView.frame.origin.x, mTextView.frame.origin.y, [image size].width, [image size].height), cgImage); </code></pre> <p>Any suggestions?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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