更改NSView的转角半径应该很简单,但是我收到错误消息“严重错误:无法解开Optional.None”。我是否有可能用10.9而不是10.10进行此操作,这是由于框架差异而发生的?或代码错误。
class aRoundView: NSView {
let cornerRad = 5.0
init(frame: NSRect) {
super.init(frame: frame)
self.layer.cornerRadius = cornerRad
}
override func drawRect(dirtyRect: NSRect)
{
super.drawRect(dirtyRect)
NSColor.redColor().setFill()
NSRectFill(dirtyRect)
}
}
叫它
func applicationDidFinishLaunching(aNotification: NSNotification?) {
let aView = mainViewTest(frame: NSMakeRect(0, 0, 100, 100))
self.window.contentView.addSubview(aView)
}
实际上,不仅如此。使用self.layer进行的任何迭代都会产生相同的结果,backgroundcolor等。
这是因为self.layer
是一个可选值,当前未设置。self.wantsLayer = true
在之前添加self.layer.cornerRadius
,以确保正确layer
存在。
init(frame: NSRect) {
super.init(frame: frame)
self.wantsLayer = true
self.layer.cornerRadius = cornerRad
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句