I have a custom UIView class that has UILabel as a sub. I want to set the font size of the label in the interface builder so that I make a computed fontSize property that receives and sets the font point size of the UILabel .
@IBDesignable class UIMongolLabel: UIView { private let view = UILabel() let mongolFontName = "ChimeeWhiteMirrored" // font is always the same @IBInspectable var fontSize: CGFloat { get { if let font = view.font { return font.pointSize } else { return 0.0 } } set { view.font = UIFont(name: mongolFontName, size: newValue) } } // ... }
This works fine if the user sets a value for the font size:

But if the user simply adds a new user view, the font size is empty.

The answers here say that it makes no sense to have a default value for a computed property in Swift, but what if I want a default for Interface Builder? I would like to say "17" or something else. What should I do?
source share