斯威夫特+ NSViewController背景色(Mac应用程序) [英] Swift + NSViewController background color (Mac App)

查看:2114
本文介绍了斯威夫特+ NSViewController背景色(Mac应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想改变我的视图的背景颜色。视图控制器类是 NSViewController 键入。

I am trying to change the background color of my View. The View Controller class is NSViewController type.

这可怎么办呢?在iOS中的UIKit(的UIViewController )有 self.view.backgroundColor ,但 NSViewController 不具有

How this can be done? In iOS UIKit (UIViewController) there is self.view.backgroundColor, but NSViewController doesn't have that.

和第二个问题是我如何改变应用程序标题栏的颜色?我觉得背景颜色不会影响到。

And second problem is how can I change the color of the applications Title Bar? I think the background color doesn't affect to that.

Mac适用的,语言的斯威夫特。 X $ C $ 6.1Ç

Mac application, language Swift. XCode 6.1.

推荐答案

我设法改变主视图的背景颜色。 NSViewController没有backgroundColor属性着实让我用属于NSViewController的NSView的图层属性。这里是code。

I managed to change background color of main view. NSViewController does not have backgroundColor property indeed, so I used the layer property of NSView that belongs to NSViewController. Here is the code.

class ViewController: NSViewController {

    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.wantsLayer = true

    }

    override var representedObject: AnyObject? {
        didSet {
        // Update the view, if already loaded.
        }
    }

    override func awakeFromNib() {
        if self.view.layer != nil {
            let color : CGColorRef = CGColorCreateGenericRGB(1.0, 0, 0, 1.0)
            self.view.layer?.backgroundColor = color
        }

    }
}

这将初始化红色背景视图控制器。

It will initialize the view controller with red background.

有关标题栏的颜色,我创建NSWindowController它assinged从故事板主窗口控制器。这里是code。

For Title Bar color, I created NSWindowController and assinged it to main window controller from storyboard. Here is the code.

class MainWindow: NSWindowController {

    override func windowDidLoad() {
        super.windowDidLoad()

        super.window?.backgroundColor = NSColor(calibratedRed: 0.0, green: 1.0, blue: 0.0, alpha: 1.0)
    }

}

我希望这会有所帮助。

I hope this will help.

这篇关于斯威夫特+ NSViewController背景色(Mac应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆