How to change the color of UILabel text to match the color of the background image?

I want to change the text color of the label to match the color of the background image. The background image is on UIScrollView, and UILabelon top of it. When scrolling is viewed, the color of the cue should be changed depending on the background color.

Basically, something like, if the label was on the yellow part of the image, it would be black, and if it was on the blue part of the image, it would be white.

See image below:

if the label was on the yellow part of the image, it would be black, and if it was on the blue part of the image, it would be white

Thanks at Advance ...

+4
source share
1 answer

UIView, , hiddenView , contentsize scorllview, image, scrollview, .

scrollViewDidScroll

 - (void)scrollViewDidScroll:(UIScrollView *)scrollView 
 {
     CGRect visibleRect;
     visibleRect.origin = scrollView.contentOffset;
     visibleRect.size = scrollView.bounds.size;

     float theScale = 1.0 / scale;
     visibleRect.origin.x *= theScale;
     visibleRect.origin.y *= theScale;
     visibleRect.size.width *= theScale;
     visibleRect.size.height *= theScale;

     CGImageRef imageRef = CGImageCreateWithImageInRect((CGImageRef)hiddenView.layer.contents, visibleRect);
     UIImage *BackImage = [UIImage imageWithCGImage:imageRef];
     [YourLabel setTextColor:[UIColor colorWithPatternImage:BackImage];
 }

, , .

+1

All Articles