• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Relation of UIView layer to drawRect:
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Relation of UIView layer to drawRect:


  • Subject: Relation of UIView layer to drawRect:
  • From: "David F." <email@hidden>
  • Date: Tue, 24 Aug 2010 21:47:20 -0600

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@hidden)

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:

This email sent to email@hidden

  • Follow-Ups:
    • Re: Relation of UIView layer to drawRect:
      • From: Luke Hiesterman <email@hidden>
  • Prev by Date: Re: Document Cursor
  • Next by Date: Re: Relation of UIView layer to drawRect:
  • Previous by thread: Re: Navigation Services
  • Next by thread: Re: Relation of UIView layer to drawRect:
  • Index(es):
    • Date
    • Thread