top of page

Mix It Up: Combining Font Weights in SwiftUI Text 🎭🤣

Updated: Mar 25, 2023

Hey there, SwiftUI enthusiasts! 🥳 Are you tired of plain old uniform text in your apps? Dreaming of a world where you can mix and match font weights like a typographic DJ? 🎧🎨 Well, look no further! In this one-minute read, we’re going to teach you how to spice up your Text views by combining different font weights. Let's dive right in! 💦



The Magic Trick: Two Texts, One Line ✨

The secret to combining font weights in SwiftUI is to use multiple Text views and connect them in a single line. It's like creating a typographic conga line! 🕺💃 Let's see it in action:

struct ContentView: View {
    var body: some View {
        HStack {
            Text("Bold & ")
                .fontWeight(.bold)
            Text("Beautiful")
                .fontWeight(.regular)
        }
    }
}

Boom! 💥 Just like that, we have a Text view with two different font weights. Let's break it down:

  1. We create an HStack to align our Text views horizontally.

  2. We set the .fontWeight(.bold) on the first Text and .fontWeight(.regular) on the second.

Now, our text is as diverse as the world around us! 🌈

More Fun with Font Weights 🎢

Feeling adventurous? 😏 Try combining other font weights like .semibold, .medium, or even .ultraLight! Here's an example:

struct ContentView: View {
    var body: some View {
        HStack {
            Text("Life's a ")
                .fontWeight(.semibold)
            Text("mix")
                .fontWeight(.heavy)
            Text(" of ")
                .fontWeight(.ultraLight)
            Text("fonts!")
                .fontWeight(.medium)
        }
    }
}

And there you have it — a fun and engaging way to mix font weights in SwiftUI Text views. Your users will never know what hit 'em! 🤩🎉 Remember, variety is the spice of life, so don't be afraid to get creative with your text!

5 views0 comments
bottom of page