iOS 7/8 Objective C - apply blendmode to views

540 views Asked by At

I would like to apply a saturation blendMode using a UIView on other views, like this :

Example BlendMode : Example

I have a UILabel and UIImageView in the view of my ViewController, plus a BlendView which overwrites drawRect method.

- (void) drawRect:(CGRect)area
{
    CGContextRef context = UIGraphicsGetCurrentContext();
    CGContextSaveGState(context);

    [[UIColor whiteColor] setFill];
    CGContextSetBlendMode(context, kCGBlendModeSaturation);
    CGContextFillRect(context, self.bounds);
    CGContextRestoreGState(context);
}

However, I only have a black square if kCGBlendModeSaturation is given and a white square if kCGBlendModeMultiply give - the blendmode isn't applied. I have set the BlendView as not opaque and tested with different alpha value, no changes.

P.S.: I wish the blendmode to be applied on any views, not only images.

1

There are 1 answers

1
Cyrille On

You can't apply a blend mode to a single view and hope it'll have any effect on the views below, like you would with layers in Photoshop (the only compositing you can do between two separate views are change their opacity).

The only thing you can do is, on a single view's drawRect, draw with a specific fill mode over the previous drawing instructions.