Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.
This repository was archived by the owner on May 28, 2025. It is now read-only.

CGContextSetShadow does not work with transparency layers #584

@adein

Description

@adein

Issue Description

Trying to use CGContextSetShadow with CGContext(Begin/End)TransparencyLayer does not result in a shadow.

Reproduction Steps
  1. Enable shadows with CGContextSetShadow
  2. Begin a transparency layer
  3. Draw several shapes
  4. End the transparency layer
Expected Behavior

The shapes drawn in the transparency layer should have a unified shadow, as if the shapes were one whole shape with a shadow.

Observed Behavior

No shadow is drawn at all.

Pull Request, Test Case, or Sample Code

See this URL for how Apple expects it to work.

    CGContextRef context = UIGraphicsGetCurrentContext();
    CGFloat maxWidth = rect.size.width;
    CGFloat maxHeight = rect.size.height;

    // White background
    CGContextSetFillColorWithColor(context, [UIColor whiteColor].CGColor);
    CGContextFillRect(context, CGRectMake(0, 0, maxWidth, maxHeight));

    // Rect Size
    CGFloat rectWidth = maxWidth / 2.0;
    CGFloat rectHeight = rectWidth;

    // Enable shadow
    CGSize shadowOffset = CGSizeMake(10, 20);
    CGContextSetShadow(context, shadowOffset, 10);

    // Begin Transparency
    CGContextBeginTransparencyLayer(context, NULL);

    CGContextSetFillColorWithColor(context, [UIColor redColor].CGColor);
    CGContextFillRect(context, CGRectMake(rectWidth / 2 + 25, maxHeight / 2 - rectHeight / 2 - 50, rectWidth, rectHeight));
    CGContextSetFillColorWithColor(context, [UIColor greenColor].CGColor);
    CGContextFillRect(context, CGRectMake(rectWidth / 2 - 25, maxHeight / 2 - rectHeight / 2 + 25, rectWidth, rectHeight));
    CGContextSetFillColorWithColor(context, [UIColor blueColor].CGColor);
    CGContextFillRect(context, CGRectMake(rectWidth / 2 - 50, maxHeight / 2 - rectHeight / 2, rectWidth, rectHeight));

    // End Transparency
    CGContextEndTransparencyLayer(context);

Metadata

Metadata

Assignees

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions