I've created a custom UIView where I'll eventually have 10 zones a user can tap. When a zone is tapped, I want to overlay a low-alpha layer to indicate their selection.
Unfortunately, when I tap a section, the CALayer I've created is drawing outside the bounds of my custom view. It seems as though both my x and y coordinates are off.
Here is the drawRect method inside my custom view:
- (void)drawRect:(CGRect)dirtyRect
{
if (touchPoint.x > 0 || touchPoint.y > 0){
CGRect bounds = [self bounds];
float widthOfArea = bounds.size.width / 10.0;
float sectionNumber = round(touchPoint.x / widthOfArea);
touchOverlayLayer = [[CALayer alloc] init];
[touchOverlayLayer setBounds:CGRectMake(0.0, 0.0, widthOfArea, bounds.size.height)];
[touchOverlayLayer setPosition:CGPointMake(widthOfArea * sectionNumber, self.bounds.origin.y)];
UIColor *greyish = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:.5];
CGColorRef cggreyish = [greyish CGColor];
[touchOverlayLayer setBackgroundColor:cggreyish];
[[self layer] addSublayer:touchOverlayLayer];
}
}
And the resulting display is attached.