在swift中以编程方式清除NSView [英] Clear NSView programmatically in swift
本文介绍了在swift中以编程方式清除NSView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个 NSView
连接到自定义类。
这个视图有一些绘图:
I have a NSView
connected to a custom class.
There's some drawing on that view:
class LineDrawer: NSView {
var linear = NSBezierPath()
var storage = NSUserDefaults.standardUserDefaults()
override func drawRect(dirtyRect: NSRect) {
var color = NSColor()
if let newLoadedData = storage.objectForKey("color") as? NSData {
if let currentColor = NSUnarchiver.unarchiveObjectWithData(newLoadedData) as? NSColor {
color = currentColor
}
}
color.set()
linear.lineWidth = CGFloat(storage.integerForKey("width"))
linear.stroke()
}
override func mouseDown(theEvent: NSEvent) {
super.mouseDown(theEvent)
let location = theEvent.locationInWindow
var lastPt = theEvent.locationInWindow
lastPt.y -= frame.origin.y
linear.moveToPoint(lastPt)
}
override func mouseDragged(theEvent: NSEvent) {
super.mouseDragged(theEvent)
var newPt = theEvent.locationInWindow
newPt.y -= frame.origin.y
linear.lineToPoint(newPt)
needsDisplay = true
}
}
我需要写一个函数来完全清除该视图。
And now I need to write a function to completely clear that view.
推荐答案
不太确定您的意思是否完全清除该视图,但不能只是填充一个纯色? / p>
Not too sure what you mean by completely clear that view but can't you just fill it with a solid colour?
[[NSColor windowBackgroundColor] setFill];
NSRectFill(self.bounds);
(尚未达到Swift热度的速度)
(Not up to speed with the Swift hotness yet)
更新
我改善了我的Swift chops。
update I improving my Swift chops behold!
NSColor.windowBackgroundColor().setFill()
NSRectFill(self.bounds)
这篇关于在swift中以编程方式清除NSView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文