Xcode - Change global default font in storyboard

Very similar to how we can set the global hue in the storyboard, is it possible to set the global font family as something else? For example, I want to change the default Global / Standard from System to Source Sans Pro 16pt . However, what I have to do (as far as I know) is one of the following:

  • Change the font of each label, button, textField, etc. in the storyboard.
  • Define it using the Swift ViewDidLoad Code (for example this question ) or through extensions as described in this question .

My problem with (2) is that I am not getting Visual Feedback, as in (1), using storyboards. On the other hand, this is also not very eloquent, since I have to manually install it anyway.

So, is there a way to change / set the default Storyboard font?

+6
source share
1 answer

You can use the Appearance API to ensure that all controls have the same font (at run time)

Take a look at the question how to set a font for UIButton with appearance.

For UILabel and UITextView, follow these steps: This can be done in the AppDelegate application(_:didFinishLaunchingWithOptions:)

 let labelAppearance = UILabel.appearance() labelAppearance.font = UIFont.myFont() let textFieldAppearance = UITextView.appearance() textFieldAppearance.font = UIFont.myFont() 

The previous solution, however, would not update the storyboard.

To visually see the changes in the storyboard, you can look in the function

 prepareForInterfaceBuilder() 

Here is the answer that explains how to get a visual update in the storyboard, but for this you will need to use custom classes for your text fields, buttons, etc.

Sample code according to the link above:

 @IBDesignable public class MyUILabel: UILabel { public override func awakeFromNib() { super.awakeFromNib() configureLabel() } public override func prepareForInterfaceBuilder() { super.prepareForInterfaceBuilder() configureLabel() } func configureLabel() { font = UIFont(name: Constants.DefaultFont, size: 40) } } 
+2
source

All Articles