问题
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:
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:
回答1:
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
来源:https://stackoverflow.com/questions/38906727/ibdesignable-view-not-rendering