IBDesignable view not rendering

2019-07-22 19:50发布

I have a simple @IBDesignable view that I have specified as the base class for the top level view in a scene in my macOS storyboard. For example:

@IBDesignable
class OvalView: NSView {
    override func draw(_ dirtyRect: NSRect) {
        super.draw(dirtyRect)

        NSColor.red.setFill()
        NSBezierPath(ovalIn: bounds).fill()
    }
}

When I run the app, this view appears fine. But this designable view is not rendered in my scene in Interface Builder:

enter image description here

Note, this problem only manifests itself when the view in question is the top level view of the scene. If I do it for subviews, it works fine:

enter image description here

1条回答
爷的心禁止访问
2楼-- · 2019-07-22 20:28

The issue is that Interface Builder does not appear to properly render a @IBDesignable macOS view in Interface Builder if that view is the top level view in a scene. It will in iOS, but not macOS. In macOS, it only renders the designable view in Interface Builder if it is a subview, but not the top level view.

I have filed a bug report. #27817119

查看更多
登录 后发表回答