Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7160683
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:26:20+00:00 2026-05-28T13:26:20+00:00

I’m struggling to find the missing piece in my code.I have a class which

  • 0

I’m struggling to find the missing piece in my code.I have a class which derives from UIView(customView) and also have a class that derives from CALayer (customLayer) and implements the drawLayer:inContext delegate method of the CALayer class.I do that because I want to use the customLayer as a clipping mask and so I need the drawLayer: inContext method which is not called when I start the application.
Here is a snippet of my code

@implementation CustomView

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor lightGrayColor]; 
        // Initialization code
        CustomLayer *customLayer= [CALayer layer];     
        customLayer.backgroundColor= [UIColor colorWithRed:0 green:0.6 blue:0.2  alpha:0.4].CGColor;
        customLayer.frame = self.bounds;
        customLayer.delegate=customLayer;
        [customLayer setNeedsDisplay];
        [self.layer addSublayer:customLayer];
     }
  return self;
}

and the customLayer implementation:

@implementation CustomLayer

-(void) drawLayer:(CALayer *)layer inContext:(CGContextRef)ctx
{
    NSLog(@"drawLayer:inContext");
    CGContextBeginPath (ctx);
    CGContextAddEllipseInRect(ctx, self.frame);
    CGContextClosePath (ctx);
    CGContextClip (ctx);
}

I really can’t figure out what is going on.Any advices will be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T13:26:21+00:00Added an answer on May 28, 2026 at 1:26 pm

    Updating based on conversation in comments

    First, this line:

    CustomLayer *customLayer= [CALayer layer];     
    

    needs to use your CustomLayer:

    CustomLayer *customLayer= [CustomLayer layer];     
    

    That said, setting the customLayer as its own delegate is a bit odd, you may actually be running into code preventing this.

    Have you tried using the - (void)drawInContext:(CGContextRef)ctx method? Generally, each CALayerDelegate method has a corresponding CALayer method that you can override in subclasses.

    -(void) drawInContext:(CGContextRef)ctx
    {
        NSLog(@"drawLayer:inContext");
        CGContextBeginPath (ctx);
        CGContextAddEllipseInRect(ctx, self.frame);
        CGContextClosePath (ctx);
        CGContextClip (ctx);
    
        // Note: this is where your original code ended, you have successfully set up a clipping path, but you haven't drawn anything to actually get clipped!
        CGContextSetRGBFillColor(context, 0, 0.6, 0.2, 0.4);
        CGContextFillRect(context, self.bounds);
    }
    

    Also, are you setting the frame (bounds/position//center) of the CustomLayer instance? I see you adding it to the layer hierarchy, but at the default 0,0 size.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a text area in my form which accepts all possible characters from
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have a bunch of posts stored in text files formatted in yaml/textile (from
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.