Skip to content
DeveloperMemos

Bolding Text in SwiftUI

SwiftUI, Swift, iOS1 min read

I've been testing out SwiftUI quite a bit lately, and it is giving me high hopes about the future of native development(although there are still a lot of rough edges). Today in this post I thought I'd write a quick note about making a Text widget use bold text instead of regular text.

It's actually not that complicated at all, all you need to do is add .bold(), and that's it. Here's a full example of this:

1import SwiftUI
2
3struct BoldTextView : View {
4
5 var body: some View {
6 HStack {
7 Text("Bold Text").bold()
8 }
9 }
10
11}
12
13struct BoldTextView_Previews: PreviewProvider {
14 static var previews: some View {
15 BoldTextView()
16 }
17}

And there you have it, the text will be bold...I kind of like how this works. In Flutter you have to add a TextStyle to the Text and it can be kind of cumbersome sometimes as you add more and more properties. It's still taking me a while to get used to indentation in SwiftUI but.