Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming you are already through with moving your imageView around the screen. Let me proceed with what to do.</p> <ol> <li>When you touch the imageView. Change the Image in it using the code that I am going to provide.</li> <li>Once you are done moving the imageView, replace the new image with the old Image</li> </ol> <blockquote> <p>new image = one with black image + black text; old image = one with black image + transparent text;</p> </blockquote> <pre><code>-(UIImage *)customImage:(NSString *)cellImageName withText:(NSString *)badgeText textColor:(UIColor*)color { UIImage *bottomImage = [UIImage imageNamed:cellImageName]; //Change the font size to change text size CGSize stringSize = [badgeText sizeWithFont:[UIFont systemFontOfSize:[UIFont systemFontSize]]]; 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 [color set]; //change this textRect to change the position of text on image CGRect textRect = CGRectMake((bottomImage.size.width - stringSize.width)/2.0f, bottomImage.size.height - stringSize.height, stringSize.width, stringSize.height); [badgeText drawInRect:textRect withFont:[UIFont systemFontOfSize:[UIFont systemFontSize]]]; image = UIGraphicsGetImageFromCurrentImageContext(); UIGraphicsEndImageContext(); return image; } </code></pre> <p>now before you start, throw away the label and for convenience sake (you can replace the UIImageView with CALayer, if you want to) i.e. instead of </p> <blockquote> <p><strong>imageView.image = image</strong> you can write <strong>layer.contents = (id)image.CGImage</strong></p> </blockquote> <p>Now, when u setup ur ImageView or Layer then first get the image as </p> <blockquote> <p>UIImage *image = [self customImage:@"Image Name" withText:@"Text" textColor:[UIColor blackColor]];</p> </blockquote> <p>and put this image into the imageView or layer</p> <p>Now, when you start moving your imageview or layer. In <code>touchesBegan</code> or whichever method is Your first responder for the touch. Replace the image again as </p> <blockquote> <p>UIImage *image = [self customImage:@"Image Name" withText:@"Text" textColor:[UIColor clearColor]];</p> </blockquote> <p>And in <code>touchesEnded</code> replace the image again with first call of black color text.</p> <p>This should get you going. Let me know in case of issues.</p> <p>The above method provide write the text on top of your image, and creates a new image with text in it. Hence you can throw away the label.</p> <p>Cheers, have fun.</p> <p><strong>EDIT</strong></p> <p>try this, have not tried it myself but should work</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 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; } } </code></pre> <p>call this method in touchesBegan and touchesMoved. if the animation stutters (which shud not happen), try calling it inside an animation block.</p> <p>try this and let me know.</p> <p><strong>EDIT: LINK TO SAMPLE APP</strong></p> <blockquote> <p>I have created a sample app showing how to clear overlapping areas. Check it. <a href="https://www.dropbox.com/sh/5z45gkwgmstfyvu/lwzbUyh6IR" rel="nofollow">https://www.dropbox.com/sh/5z45gkwgmstfyvu/lwzbUyh6IR</a></p> </blockquote>
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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