NSRulerView background color

  • Hi,
    as you know the default background color of an NSRulerView is the window
    with the horizontal gray lines. I would indeed set a gray color. So I
    subclassed the NSRulerView and coded

    -(void)drawHashMarksAndLabelsInRect:(NSRect)aRect
    {
        [[NSColor colorWithCalibratedWhite:0.85 alpha:1.0] set];
        NSRectFill(aRect);

        [super drawHashMarksAndLabelsInRect:aRect];
    }

    It works so and so, but sometimes the rulerView doesn't get refreshed and I
    still see portions of the background window with the gray horizontal lines
    pattern. I have tried to fill the rect in the drawRect method, but it is
    worse. Any idea?

    Best Regards
    --
    Lorenzo
    email: <archidea...>
  • Hello Lorenzo,

    It just so happens NSRulerView has the following method:

    - (void)drawBackgroundInRect:(NSRect)rect;

    It should suffice very nicely. Don't call super with this though, that
    will mess it up. The below snippet should work fine.

    - (void)drawBackgroundInRect:(NSRect)rect
    {
      [[NSColor colorWithCalibratedWhite: 0.85 alpha: 1.0] set];
      [NSBezierPath fillRect: rect];
    }

    Have fun!
    Peace, Alan

    --
    // Quotes from yours truly -------------------------
    "You don't forget, you just don't remember."
    "Maturity resides in the mind."
    "Silence is the Universe's greatest gift."
    "When the World realizes that religion really is unnecessary, then it
    shall evolve."
  • Thank you Alan,
    it works well!

    Best Regards
    --
    Lorenzo
    email: <archidea...>

    > From: Alan Smith <alanrogersmith...>
    > Date: Wed, 02 May 2007 12:16:24 -0400
    > To: Lorenzo <archidea...>
    > Cc: <cocoa-dev...>
    > Subject: Re: NSRulerView background color
    >
    > Hello Lorenzo,
    >
    > It just so happens NSRulerView has the following method:
    >
    > - (void)drawBackgroundInRect:(NSRect)rect;
    >
    > It should suffice very nicely. Don't call super with this though, that
    > will mess it up. The below snippet should work fine.
    >
    > - (void)drawBackgroundInRect:(NSRect)rect
    > {
    > [[NSColor colorWithCalibratedWhite: 0.85 alpha: 1.0] set];
    > [NSBezierPath fillRect: rect];
    > }
    >
    > Have fun!
    > Peace, Alan
    >
    >
    > --
    > // Quotes from yours truly -------------------------
    > "You don't forget, you just don't remember."
    > "Maturity resides in the mind."
    > "Silence is the Universe's greatest gift."
    > "When the World realizes that religion really is unnecessary, then it
    > shall evolve."