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

  • SEARCH
  • Home
  • 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 4050154
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:02:05+00:00 2026-05-20T14:02:05+00:00

I have asked (and answered) a very similar question before. That question was able

  • 0

I have asked (and answered) a very similar question before. That question was able to be solved because I knew the dirtyRect, and thus, knew where I should draw the image. Now, I am seeing the same behavior with an subclassed NSButtonCell:

enter image description here

In my subclass, I am simply overriding the drawImage:withFrame:inView method to add a shadow.

- (void)drawImage:(NSImage *)image withFrame:(NSRect)frame inView:(NSView *)controlView {   

    NSGraphicsContext *ctx = [NSGraphicsContext currentContext];
    [ctx saveGraphicsState];

    // Rounded Rect
    NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:frame cornerRadius:kDefaultCornerRadius];
    NSBezierPath *shadowPath = [NSBezierPath bezierPathWithRoundedRect:NSInsetRect(frame, 0.5, 0.5) cornerRadius:kDefaultCornerRadius]; // prevents the baground showing through the image corner

    // Shadow
    NSColor *shadowColor = [UAColor colorWithCalibratedWhite:0 alpha:0.8];
    [NSShadow setShadowWithColor:shadowColor
                  blurRadius:3.0
                      offset:NSMakeSize(0, -1)];
    [[NSColor colorWithCalibratedWhite:0.635 alpha:1.0] set];
    [shadowPath fill];
    [NSShadow clearShadow];

    // Background Gradient in case image is nil
    NSGradient *gradient = [[NSGradient alloc] initWithStartingColor:[UAColor grayColor] endingColor:[UAColor lightGrayColor]];
    [gradient drawInBezierPath:shadowPath angle:90.0];
    [gradient release];

    // Image
    if (image) {
        [path setClip];
        [image drawInRect:frame fromRect:CGRectZero operation:NSCompositeSourceAtop fraction:1.0];
    }

    [ctx restoreGraphicsState];

}

It seems all pretty standard, but the image is still drawing outside of the containing scrollview bounds. How can I avoid this?

  • 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-20T14:02:06+00:00Added an answer on May 20, 2026 at 2:02 pm

    You shouldn’t call -setClip on an NSBezierPath unless you really mean it. Generally you want ‑addClip, which adds your clipping path to the set of current clipping regions.

    NSScrollView works by using its own clipping path and you’re blowing that path away before drawing your image.

    This tripped me up for a long time too.

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

Sidebar

Related Questions

This is very similar to a question I have already asked (and had answered)
I know that this question must have been asked and answered a million times,
Somebody asked similar question not long ago. But nobody answered comprehensively. Assume I have:
I have asked this question before and the problem was half solved in the
Although this question have been asked and answered before, including on this website, I
I realize similar questions have been asked and answered but doing everything that is
I am pretty much sure that this question have been asked and answered several
This morning I asked this very similar question, and it was answered beautifully. However,
I have asked a similar question previously, but 1. no one answered and 2.
I asked a question about bigints yesterday which was kindly answered. However, I have

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.