cocoa – 窗口顶部的iTunes或Xcode样式信息框

前端之家收集整理的这篇文章主要介绍了cocoa – 窗口顶部的iTunes或Xcode样式信息框前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有什么选择在 Cocoa的iTunes顶部重新创建框,或者像Apple在XCode 4中使用的那样?

这只是一个简单的图像,控制在顶部?或者它是一个具有一些自定义风格魔法的NSBox

解决方法

我必须为我的一个项目编写类似的代码.对于我的解决方案,您将需要此 tutorial中的示例代码中提供的两个类别.此代码将绘制背景渐变和必要的阴影,您可以在控件内添加其他内容.目前,代码将绘制Xcode样式渐变作为背景,但如果您需要,可以将其注释掉并取消注释iTunes样式.希望这可以帮助.
#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],[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],[NSColor colorWithCalibratedRed:0.871 green:0.894 blue:0.918 alpha:1.0],[NSColor colorWithCalibratedRed:0.831 green:0.851 blue:0.867 alpha:1.0],[NSColor colorWithCalibratedRed:0.82 green:0.847 blue:0.89 alpha: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];
}

猜你在找的iOS相关文章