macos - 如何为这样的应用程序窗口着色?

标签 macos cocoa tint

我对 OSX 开发非常陌生。

如何像此应用程序一样将应用程序着色为深灰色?

enter image description here

可以从界面生成器中做到这一点吗?如果没有,我该如何从代码中做到这一点?

最佳答案

要更改窗口标题栏颜色,请将窗口设置为 IB 中的纹理。然后在相应的 View Controller /应用程序委托(delegate)中更新窗口颜色。

NSColor *grayColor = [NSColor colorWithCalibratedRed:64/255.0f
                                               green:64/255.0f
                                                blue:64/255.0f
                                               alpha:1.0];
[self.window setBackgroundColor:grayColor];

现在窗口会像这样:

enter image description here

使用工具栏:

enter image description here

请注意,当窗口设置为纹理时,整个窗口都将被纹理化。我已对 View 进行子类化并将背景设置为白色:

- (void)drawRect:(NSRect)dirtyRect
{
    [super drawRect:dirtyRect];
    [[NSColor whiteColor] setFill];
    NSRectFill(dirtyRect);
}

否则窗口会像这样:

enter image description here

关于macos - 如何为这样的应用程序窗口着色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24505977/

相关文章:

macos - 用于了解用户何时登录 MAC 的守护进程

html - 文本色调的 CSS 等价物

macos - 如何将色调颜色应用于 NSButton(内联样式) cocoa

android - AppCompat 工具栏上的 MenuItem 着色

php - nginx:Mac OS X 上带有 Curl/https 的 502 Bad Gateway

eclipse - 在 OS X 上使用 Eclipse 设置 Google 测试 (gtest)

ios - xamarin 表单 ios 版本构建挂起

objective-c - 值得学习的编写良好的开源 Cocoa 应用程序?

c++ - Obj-C++ 头文件中的 AppKit 对象?

macos - 如何知道 NSDocument 是否被锁定?