我已經通過這裏和其他博客的許多線程,但無法解決這個問題。我在窗口的內容視圖中添加了一個子視圖。這裏是storyboard--如何爲NSView顯示陰影?
我已經拖了出來customView出口到視圖控制器和這裏是視圖控制器的代碼 - 我在加入QuartzCore框架工作
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層支持。 –
我已經爲窗口的內容視圖添加了self.view.wantsLayer = true。紅色視圖是內容視圖本身的子視圖。 – Abhishek