Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iTunes or Xcode style information box at top of window

What are my options to recreate the box at the top of iTunes in Cocoa, or like Apple uses in XCode 4?

itunes

Is this just a plain image, with control on top? Or is it an NSBox with some custom style magic?

like image 619
eric Avatar asked May 10 '11 13:05

eric


People also ask

What is the top bar of iOS called?

A status bar appears along the upper edge of the screen and displays information about the device's current state, like the time, cellular carrier, and battery level.

What is Apple style guide?

The Apple Style guide provides guidelines to help maintain a consistent voice in Apple materials, including documentation, reference materials, training, and user interfaces.

Where is Xcode devices and simulators window?

The basic way to open a list of simulators is to use Xcode -> Window -> Devices and Simulators. Here you can create and manage all available simulators.

What is the Apple UI called?

Aqua is the graphical user interface, design language and visual theme of Apple's macOS operating system.


2 Answers

I had to code up something similar for one of my projects. For my solution, you will need the two categories available from the sample code in this tutorial. This code will draw the background gradient and the necessary shadows, it would be up to you to add additional content inside the control. Currently, the code will draw the Xcode style gradient as the background, but you could comment that out and uncomment the iTunes style one if that is what you need. Hope this helps.

#import "NSShadow+MCAdditions.h" // from the tutorial linked to above
#import "NSBezierPath+MCAdditions.h" // from the same tutorial

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

    if (kDropShadow == nil) {
        kDropShadow = [[NSShadow alloc] initWithColor:[NSColor colorWithCalibratedWhite:.863 alpha:.75] offset:NSMakeSize(0, -1.0) blurRadius:1.0];
        kInnerShadow = [[NSShadow alloc] initWithColor:[NSColor colorWithCalibratedWhite:0.0 alpha:.52] offset:NSMakeSize(0.0, -1.0) blurRadius: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];
    bounds.size.height -= 1.0;
    bounds.origin.y += 1.0;

    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 strokeInside];

    [path fillWithInnerShadow:kInnerShadow];
}
like image 75
willbur1984 Avatar answered Dec 12 '22 09:12

willbur1984


I'd write a custom NSView. Draw the background and border yourself in drawRect:. You can use NSGradient to draw the filled background, or alternatively you could save it as an image and draw that. You could probably use a white NSShadow to get the embossed effect for the border.

Finally, to get your text on there, you could just add text fields as subviews of your new custom view.

like image 26
Amy Worrall Avatar answered Dec 12 '22 10:12

Amy Worrall