Fattie
Fattie

Reputation: 12582

Set defaultTextAttributes using User Defined Runtime Attributes?

Say you are setting

 field
      .defaultTextAttributes
      .updateValue(20.0, forKey: NSAttributedStringKey.kern.rawValue)

(BTW you do that to space out text, like t h i s.)

in fact, is there a way to set that using User Defined Runtime Attributes,

right on the storyboard in Xcode?

Upvotes: 2

Views: 628

Answers (1)

matt
matt

Reputation: 534885

No, there is not. User Defined Runtime Attributes works only where key-value coding would work, with a limited range of value types. A moment's thought will reveal that your code can't be expressed in that way.

You could, however, subclass to define a custom property and set it to 20 in User Defined Runtime Attributes, and respond with a setter observer to run the code you've shown. That way, different fields can have different kern values depending on a setting in the storyboard.

(If you're going to do that, you might as well make this property IBInspectable; IBInspectable effectively is User Defined Runtime Attributes, with a different interface.)

Upvotes: 1

Related Questions