gpt4 book ai didi

cocoa - 窗口顶部的 iTunes 或 Xcode 风格信息框

转载 作者:行者123 更新时间:2023-12-03 16:05:56 28 4
gpt4 key购买 nike

我可以选择哪些选项来在 Cocoa 中重新创建 iTunes 顶部的框,或者像 Apple 在 XCode 4 中使用的那样?

itunes

这只是一个普通的图像,控件位于顶部吗?或者它是一个带有一些自定义样式魔法的 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],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];
}

关于cocoa - 窗口顶部的 iTunes 或 Xcode 风格信息框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5951196/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com