Here is a more modern solution. First, create a subclass of NSView that draws on the effect you want to achieve. Here is a simple one that draws the color of the block:
class ColouredView: NSView { @IBInspectable var color: NSColor = .windowBackgroundColor override func draw(_ dirtyRect: NSRect) { color.setFill() dirtyRect.fill() } }
Now go to the pen or storyboard and drag the custom view to the left pane. We do not want it to be part of the view hierarchy, but we want it to appear under the view controller that contains the collection view. Just drag it below "First Responder". Then you can set any important properties or relationships - in my case, the background color.
Finally, right-click your collector view and connect its "background view" output to your custom view. This allows you to make all the settings in your storyboard. If you like, you can make your own look @IBDesignable but I find this usually causes more problems than it's worth it.
source share