Wednesday, June 5, 2013

UIBezierPath fillWithBlendMode alpha example in Objective C (iOS).


UIBezierPath fillWithBlendMode alpha

Paints the region enclosed by the receiver’s path using the specified blend mode and transparency values.

- (void)fillWithBlendMode:(CGBlendMode)blendMode alpha:(CGFloat)alpha

Parameters of [UIBezierPath fillWithBlendMode alpha]
blendMode
The blend mode determines how the filled path is composited with any existing rendered content.
alpha
The amount of transparency to apply to the filled path. Values can range between 0.0 (transparent) and 1.0 (opaque). Values outside this range are clamped to 0.0 or 1.0.

Discussion of [UIBezierPath fillWithBlendMode alpha]
This method fills the path using the current fill color and drawing properties (plus the specified blend mode and transparency value). If the path contains any open subpaths, this method implicitly closes them before painting the fill region.

The painted region includes the pixels right up to, but not including, the path line itself. For paths with large line widths, this can result in overlap between the fill region and the stroked path (which is itself centered on the path line).[UIBezierPath fillWithBlendMode alpha]

This method automatically saves the current graphics state prior to drawing and restores that state when it is done, so you do not have to save the graphics state yourself.

UIBezierPath fillWithBlendMode alpha example.
CGRect container = CGRectMake(conX, conY, 220, 50);
    UIBezierPath* path = [UIBezierPath bezierPathWithRoundedRect:container cornerRadius:5.0];
    [[UIColor blueColor] setFill];
    [path fillWithBlendMode:kCGBlendModeNormal alpha:0.7];

Example of [UIBezierPath fillWithBlendMode alpha].
    CGContextRef context = CGBitmapContextCreate(NULL,
                                                 maskLayer.bounds.size.width,
                                                 maskLayer.bounds.size.height,
                                                 8,
                                                 maskLayer.bounds.size.width,
                                                 NULL,
                                                 kCGImageAlphaOnly);
    UIGraphicsPushContext(context);
    CGContextSetAlpha(context, 1.0);
    CGContextFillRect(context, maskLayer.bounds);
    [boxPath fillWithBlendMode:kCGBlendModeCopy alpha:0.0];
    CGImageRef maskImage = CGBitmapContextCreateImage(context);
    maskLayer.contents = (__bridge id)maskImage;
    UIGraphicsPopContext();
    CGImageRelease(maskImage);
    CGContextRelease(context);

End of UIBezierPath fillWithBlendMode alpha example article.