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 667451
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T23:55:48+00:00 2026-05-13T23:55:48+00:00

I have a window which has a custom NSView and has a bottom bar

  • 0

I have a window which has a custom NSView and has a bottom bar with controls on it, one of which is an NSColorWheel.

For simplicity sake the Window is 332px high, with the custom NSView being 300px high and the bottom bar being 32px high.

The bottom bar is created as part of my awakeFromNib when the app loads the window using the following code:

[[self window] setAutorecalculatesContentBorderThickness:YES forEdge:NSMinYEdge];
[[self window] setContentBorderThickness: 32.0 forEdge: NSMinYEdge];

In my custom NSView class I fill the rectangle with color. Everything works fine when the app loads using the following in my NSView class:

- (void)drawRect:(NSRect)dirtyRect
{
    dirtyRect = [self bounds];

    NSColor * mNewColor = [NSColor blackColor];
    [mNewColor set];
    [NSBezierPath fillRect:dirtyRect];
}

However, if I subsequently call a method that changes the color of the custom NSView when a color wheel in the bottom bar is changed, the bottom bar gets overwritten with the color. The following code illustrates this method (this code is in the custom NSView class:

- (void)changeBackgroundColor:(NSNotification *)notification
{
    NSLog(@"Changed background color");

    NSRect mRect = [self bounds];
    NSColor * mNewColor = [theColorWell color];
    [mNewColor set];
    [NSBezierPath fillRect:mRect];
    [self setNeedsDisplay:YES];
}

Resizing the window instantly corrects the problem, but obviously I don’t want the user to have to resize the window for an obvious bug!

What I don’t understand is why my bounds appear to be mapping to the parent window and not the custom NSView when I call setNeedsDisplay and yet the bound correctly adjust when I resize the window using the mouse (even if just by 1 pixel).

Do I somehow need to account for the bottom bar on the redraw?

Any and all help much 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-13T23:55:48+00:00Added an answer on May 13, 2026 at 11:55 pm

    You should do all your drawing in the drawRect: method of your custom NSView. Cocoa automatically sets up the graphics context for you when it calls this method – things may not draw correctly if you perform drawing operations in other methods.

    Your code in drawRect: could set the colour to the the current background colour as specified by your NSColorWell and fill the dirtyRect rectangle with this.

    Then in the other method just call [self setNeedsDisplay:YES]; and then drawRect: will automatically be called to redraw the view.

    See here for more information: http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/CocoaViewsGuide/SubclassingNSView/SubclassingNSView.html#//apple_ref/doc/uid/TP40002978-CH7-SW4 (in particular the Drawing View Content section)

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

Sidebar

Related Questions

I have a WPF Window which has a among other controls hosts a Frame.
I have a WPF application which has a main window composed from several custom
I have a custom NSView which contains a subview—for the purposes of solving this
I have a custom control which has a property of type Collection<System.Drawing.Point> . When
I have a custom UserControl which has a DependencyProperty ItemTemplate of type DataTemplate. I
lets say i have a custom widget which has a ClickHandler. Here's the example:
In my application I have a window which I popup with small messages on
I have a window in WPF which shows some media contents. This content contains
I have a main window (#1) on my webpage from which I open a
I have a WPF window for editing database information, which is represented using an

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.