在swift中以编程方式清除NSView

编程入门 行业动态 更新时间:2024-10-24 08:19:11
本文介绍了在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

本文发布于:2023-11-24 08:55:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624550.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:中以   方式   swift   NSView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!