@IBInspectable

When working in Interface Builder, you are able to modify attributes for the views that you add to the canvas. For example, you can set the background color on a view, the text on a label, and the current progress on a slider. You can add this same behavior to your own custom UIView subclasses for certain types. Let’s add in the ability for the DrawView’s current line color, finished line color, and line thickness to be customized through Interface Builder.

In DrawView.swift, declare three properties to reference these values. Give them default values and have the view flag itself for redrawing whenever these properties change.

var currentLines = [NSValue:Line]()
var finishedLines = [Line]()

@IBInspectable var finishedLineColor: ...

Get iOS Programming: The Big Nerd Ranch Guide, 6th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.