Essence of chicken Essence of chicken - 9 days ago 5
iOS Question

Is there any way of adding an abbreviation/shorthand/constant in place of a string in a Storyboard?

I've got an

@IBDesignable
UILabel
with
@IBInspectable
properties, one of which is the font name.

Having to type in long complex font names into the storyboard is tedious and error prone:

enter image description here

What I would like to do if possible is have constants in the code, such as:

let Text75Bold = "NHaasGroteskTXStd-75Bd"


And for this to be visible in the Storyboard, i.e.:

enter image description here

Is this possible?

For reference the label code is:

@IBDesignable class CustomLabel: UILabel {

@IBInspectable override var text: String? {
didSet {
decorate()
}
}

@IBInspectable var fontSize:CGFloat = 15.0 {
didSet {
decorate()
}
}

@IBInspectable var fontColor: UIColor = UIColor.red {
didSet {
decorate()
}
}

@IBInspectable var tracking: Int = 0 {
didSet {
decorate()
}
}

@IBInspectable var fontName: String = Display75Bold {
didSet {
decorate()
}
}

....

Answer

As we discussed in the comments you can have a dictionary (not inspectable) using short names as keys and long names as values and simple string as an inspectable property. In the setter of that property you can update the font using it as a key for that dictionary.