Clear NSView programmatically in swift

旧城冷巷雨未停 提交于 2019-12-06 11:56:05

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);

(Not up to speed with the Swift hotness yet)

update I improving my Swift chops behold!

NSColor.windowBackgroundColor().setFill()
NSRectFill(self.bounds)

Something like this should suffice. I used something like this in my project to clear NSView.

while curView.subviews.count > 0 {
   curView.subviews.last?.removeFromSuperview()
}

Swift 4.2 solution:

myView.subviews.removeAll()
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!