Note that there are some explanatory texts on larger screens.

plurals
  1. POErasing part of an image that overlaps with text from a UILabel
    primarykey
    data
    text
    <p>I have it where a user can move an image and uilabel around the screen. Say it is a black image and black text. I want the portion of the text that overlaps with the image to become transparent so that the background shows through and you can still read the text even though they were originally the same color. Hopefully this makes sense.</p> <p>I've found some links on erasing with touch. I'm not sure how to go about automating this with the portion of the text that overlaps. </p> <p>Maybe something like this "Masking an image with an image"? <a href="https://developer.apple.com/library/mac/#documentation/graphicsimaging/conceptual/drawingwithquartz2d/dq_images/dq_images.html" rel="nofollow noreferrer">https://developer.apple.com/library/mac/#documentation/graphicsimaging/conceptual/drawingwithquartz2d/dq_images/dq_images.html</a></p> <p><img src="https://i.stack.imgur.com/WAaMI.png" alt="Example of overlapping text"></p> <p>Here is how I move the image (and also the text)</p> <pre><code>-(void)graphicMoved:(UIPanGestureRecognizer *)recognizer { CGPoint translation = [recognizer translationInView:self.view]; recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, recognizer.view.center.y + translation.y); [recognizer setTranslation:CGPointMake(0, 0) inView:self.view]; } </code></pre> <hr> <p><strong>Added Code</strong> I'm calling the creatAlphaClippedImage on a button click after I place the text and image partially overlapping. The image is imageMerge and the label is labelTest.</p> <p>All I do is assign them at the beginning and then at the end, take the output impage and assign it to imageMerge.image which is added to my view with interface builder in the corner just to test. I don't know what a nslog should show, but its not empty.</p> <pre><code>-(void)createAlphaClippedImage { UIImageView *imageView = nil;//this will b your imageView, property that u are holding to UILabel *label = nil;//this will be your label, property that u are holding to imageView=imageMerge; label=labelTest; if (CGRectIntersectsRect(imageView.frame, label.frame)) { UIImage *bottomImage = imageView.image; UIImage *image = nil; UIGraphicsBeginImageContextWithOptions(bottomImage.size, NO, 0.0); CGRect imageRect = CGRectMake(0.0f, 0.0f, bottomImage.size.width, bottomImage.size.height); [bottomImage drawInRect:imageRect]; //the color that u want the text to have [[UIColor clearColor] set]; //change this textRect to change the position of text on image CGRect textRect = CGRectMake(CGRectGetMinX(label.frame) - CGRectGetMinX(imageView.frame), CGRectGetMinY(label.frame) - CGRectGetMinY(imageView.frame), CGRectGetWidth(label.frame), CGRectGetHeight(label.frame)); [label.text drawInRect:textRect withFont:label.font]; image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); imageView.image = image; imageMerge.image=image; NSLog(@"ImageMerge %@\n",imageMerge.image); } } </code></pre>
    singulars
    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.
 

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