Got it.  Thanks.

David

On Aug 24, 2010, at 11:41 PM, Luke Hiesterman wrote:

> Adding a sublayer to self.layer works just like adding a subview to self. 
> Sublayers are drawn on top of their superlayers. In this case the superlayer 
> is your view, so the image in the sublayer will be rendered on top of 
> whatever you draw in drawRect:
> 
> Luke
> 
> Sent from my iPhone.
> 
> On Aug 24, 2010, at 8:47 PM, David F. <[email protected]> wrote:
> 
>> 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/luketheh%40apple.com
>> 
>> This email sent to [email protected]

_______________________________________________

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