What is the relationship of a UIView's layer (and its sublayers) to what 
happens when that UIView's drawRect: is called?  I would expect the code below 
to draw a diagonal line across (i.e. on top of) the image, but it looks like 
the line is drawn behind the image.  In other words, all I see is the image.

@implementation MyView

- (void)awakeFromNib {
        CALayer *imgLayer = [CALayer layer];
        imgLayer.position = CGPointMake(self.bounds.size.width / 2, 
self.bounds.size.height / 2);
        imgLayer.bounds = self.bounds;
        imgLayer.contents = (id)[[UIImage imageNamed: @"myimage.jpg"] CGImage];
        [self.layer addSublayer: imgLayer];
}

- (void)drawRect: (CGRect)rect {
        CGMutablePathRef path = CGPathCreateMutable();
        CGPathMoveToPoint(path, NULL, 0, 0);
        CGPathAddLineToPoint(path, NULL, self.bounds.size.width, 
self.bounds.size.height);

        CGContextRef context = UIGraphicsGetCurrentContext();
        UIColor *black = [UIColor colorWithRed: 0 green: 0 blue: 0 alpha: 0.5];
        CGContextSetStrokeColorWithColor(context, black.CGColor); 
        CGContextSetLineWidth(context, 10);
        CGContextSetLineCap(context, kCGLineCapRound);
        CGContextAddPath(context, path);
        CGContextStrokePath(context);
        CFRelease(path);
}

@end

Any hints?

Thanks,
David

_______________________________________________

Cocoa-dev mailing list ([email protected])

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to