【发布时间】:2015-12-27 20:34:15
【问题描述】:
我在这里和其他博客浏览了很多线程,但无法解决这个问题。我在窗口的内容视图中添加了一个子视图。这是故事板--
我已将 customView 的出口拖出到视图控制器,这是视图控制器的代码 -
import Cocoa
import QuartzCore
class ViewController: NSViewController {
@IBOutlet weak var customView: NSView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
self.view.wantsLayer = true
self.customView.wantsLayer = true
self.customView.layer?.backgroundColor = NSColor.redColor().CGColor
self.customView.layer?.cornerRadius = 5.0
self.customView.layer?.shadowOpacity = 1.0
self.customView.layer?.shadowColor = NSColor.blackColor().CGColor
self.customView.layer?.shadowOffset = NSMakeSize(0, -3)
self.customView.layer?.shadowRadius = 20
}
override var representedObject: AnyObject? {
didSet {
// Update the view, if already loaded.
}
}
}
我无法解决看似微不足道的问题。我错过了什么?感谢您的帮助。
【问题讨论】:
-
可能你也需要让 superview layer-backed。
-
我已经为窗口的内容视图添加了 self.view.wantsLayer = true 。红色视图是内容视图本身的子视图。
标签: macos swift cocoa calayer nsview