MacOS Playground: How can change the background color?

后端 未结 1 1034
说谎
说谎 2021-01-25 22:13

I\'m trying to change the background color of main view:

import AppKit
import PlaygroundSupport

class ViewController : NSViewController {
    override func load         


        
1条回答
  •  说谎
    说谎 (楼主)
    2021-01-25 22:46

    You just need to set your view wantsLayer property to true

    let view = views[0] as! NSView
    view.wantsLayer = true
    view.layer?.backgroundColor = NSColor.blue.cgColor
    

    0 讨论(0)
提交回复
热议问题