0

EDITED: I am trying to show an iTunes-style like information bar. This was subject was covered in detail earlier, for example at iTunes or Xcode style information box at top of window I only slightly modified the code from the above referenced link, so make it compile under a recent XCode. My code is below:

- (void)drawRect:(NSRect)dirtyRect
{
    // Drawing code here.
    static NSShadow *kDropShadow = nil;
    static NSShadow *kInnerShadow = nil;
    static NSGradient *kBackgroundGradient = nil;
    static NSColor *kBorderColor = nil;

    if (kDropShadow == nil) {
        kDropShadow = [[NSShadow alloc] init];
        [kDropShadow setShadowColor:[NSColor colorWithCalibratedWhite:.863 alpha:.75]];
        [kDropShadow setShadowOffset:NSMakeSize(0.0, -1.0)];
        [kDropShadow setShadowBlurRadius:1.0];
        kInnerShadow = [[NSShadow alloc] init];
        [kInnerShadow setShadowColor:[NSColor colorWithCalibratedWhite:0.0 alpha:0.52]];
        [kInnerShadow setShadowOffset:NSMakeSize(0.0, -1.0)];
        [kInnerShadow setShadowBlurRadius:4.0];
        kBorderColor = [[NSColor colorWithCalibratedWhite:0.569 alpha:1.0] retain];
        // iTunes style

        // kBackgroundGradient = [[NSGradient alloc] initWithColorsAndLocations:[NSColor colorWithCalibratedRed:0.929 green:0.945 blue:0.882 alpha:1.0],0.0,[NSColor colorWithCalibratedRed:0.902 green:0.922 blue:0.835 alpha:1.0],0.5,[NSColor colorWithCalibratedRed:0.871 green:0.894 blue:0.78 alpha:1.0],0.5,[NSColor colorWithCalibratedRed:0.949 green:0.961 blue:0.878 alpha:1.0],1.0, nil];

        // Xcode style
        kBackgroundGradient = [[NSGradient alloc] initWithColorsAndLocations:[NSColor colorWithCalibratedRed:0.957 green:0.976 blue:1.0 alpha:1.0],0.0,[NSColor colorWithCalibratedRed:0.871 green:0.894 blue:0.918 alpha:1.0],0.5,[NSColor colorWithCalibratedRed:0.831 green:0.851 blue:0.867 alpha:1.0],0.5,[NSColor colorWithCalibratedRed:0.82 green:0.847 blue:0.89 alpha:1.0],1.0, nil];
    }

    NSRect bounds = [self bounds];

    NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:bounds xRadius:3.5 yRadius:3.5];

    [NSGraphicsContext saveGraphicsState];
    [kDropShadow set];
    [path fill];
    [NSGraphicsContext restoreGraphicsState];

    [kBackgroundGradient drawInBezierPath:path angle:-90.0];

    [kBorderColor setStroke];
    [path stroke];
}

It is not working, however. I don't think drawRect() method ever gets called. What am I missing? Please advise.

Thank you

Community
  • 1
  • 1
Moshe Shmukler
  • 1,270
  • 2
  • 21
  • 43
  • Hi rckoenes, Sorry. I don't see your name in the stackoverflow profile. I managed to figure out why drawRect() was not being called. Still, the code is not working. I see black all over my NSView. I understand that you edited my question, but don't know how to view the diffs. If you know what I am doing wrong, please advise. I am still working on this piece. Sorry for bugging people. I am new to Cocoa. Thank you for visiting my question[s]. – Moshe Shmukler Oct 07 '14 at 10:29

1 Answers1

0

I had an extra line at the end: [path fill]; Removing it does the trick.

Moshe Shmukler
  • 1,270
  • 2
  • 21
  • 43