Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I change my font weight to medium in SwiftUI?

Tags:

swiftui

Why is the .medium system font not showing for .title style in SwiftUI?

I have also tried explicitly setting the font with Font.custom...

Text("Text").font(Font.title.weight(.light))
                    
Text("Text").font(Font.title.weight(.regular))
                    
Text("Text").font(Font.title.weight(.medium))
                    
Text("Text").font(Font.title.weight(.semibold))
                    
Text("Text").font(Font.title.weight(.bold))

Here is my output:

I am expecting .medium to be heavier than .regular.

like image 770
Gavin Jensen Avatar asked Jul 15 '19 22:07

Gavin Jensen


People also ask

How do I change the font in SwiftUI?

Hold the command key and click the text to bring up a pop-over menu. Choose Show SwiftUI Inspector and then you can edit the text/font properties.

How do I change font size in SwiftUI?

System Fontsystem(size:weight:design:) method. This method lets us specify a fixed font size that we want. Here is an example where we set the font for the second text to a fixed size of 36 points.


2 Answers

The best way to achieve this is by splitting up the font type and the font weight into two separate parts.

Text("Text")
    .font(.title)
    .fontWeight(.medium)

I hope this helps.

like image 77
IsaacRichardson Avatar answered Oct 23 '22 20:10

IsaacRichardson


 Text("Home")
    .font(.system(size: 20, weight: .bold, design: .default))

Use like this

like image 1
KurbanAli Masu Avatar answered Oct 23 '22 20:10

KurbanAli Masu