How to Set Text Font Weight in iOS SwiftUI

In this tutorial, we’re discussing an integral aspect of user interface design – font weight manipulation in SwiftUI. The weight of a font is its thickness, and using various font weights effectively can make your text more engaging, establish visual hierarchy, and emphasize key points. Let’s uncover the techniques to alter font weight in SwiftUI.

Basics: Set Font Weight

SwiftUI provides a straightforward way to set the weight of a font using the .fontWeight() modifier. This modifier accepts various predefined font weights from SwiftUI’s Font.Weight enumeration:

Text("Hello, SwiftUI!")

In this example, “Hello, SwiftUI!” is displayed with a bold font weight.

SwiftUI text font weight

Available Font Weights

SwiftUI provides several predefined font weights to choose from. These are:

  • ultraLight
  • thin
  • light
  • regular
  • medium
  • semibold
  • bold
  • heavy
  • black

Each of these font weights gives a different level of thickness to your text, allowing you to select the one that suits your design best.

Font Weight and Accessibility

SwiftUI’s .fontWeight() modifier also takes accessibility settings into account. For example, if a user has selected the “Bold Text” option in their device’s accessibility settings, all fonts will be displayed as bold regardless of the weight specified in the app.

Applying different font weights in SwiftUI is a potent tool for shaping your app’s aesthetics and improving its usability. By taking advantage of SwiftUI’s capabilities, you can alter the font weight with ease and adapt your text appearance according to your design needs.

Similar Posts

Leave a Reply