我在这里和其他博客中经历了很多线程,但无法解决这个问题.我在窗口的内容视图中添加了一个子视图.这是故事板 –
我拖出了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. } } }
我在我的项目中添加了QuartzCore框架工作 –
我无法解决看起来微不足道的事情.我错过了什么?谢谢你的帮助.
如果我添加以下行,它解决了问题 –
self.customView.shadow = NSShadow()
最终代码是 –
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.view.superview?.wantsLayer = true self.customView.wantsLayer = true self.customView.shadow = NSShadow() self.customView.layer?.backgroundColor = NSColor.redColor().CGColor self.customView.layer?.cornerRadius = 5.0 self.customView.layer?.shadowOpacity = 1.0 self.customView.layer?.shadowColor = NSColor.greenColor().CGColor self.customView.layer?.shadowOffset = NSMakeSize(0,0) self.customView.layer?.shadowRadius = 20 } override var representedobject: AnyObject? { didSet { // Update the view,if already loaded. } } }
我无法确定问题可能是这里有人会指出它.
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。