简体   繁体   中英

How do i change the font size with still the same font in Swiftui

iam trying to change the font size of an Textlabel so that i still have the same font. Every option i tried also changed the font to the basic one, but i want to use Headline or make the Text fat.

Are you looking for something like this?

import SwiftUI

struct ContentView: View {
    
    @State private var fontSize: CGFloat = 16
    
    var body: some View {
        VStack {
            Text("Hello, world!")
                .font(.system(size: fontSize))
            .padding()
            
            Button("Change font") {
                fontSize += 2
            }
        }
    }
}

This increases the font size if you click the button. You can, of course, use all kinds of methods to change the fontSize property.

It's not a headline any more, but that is, as far as I understand the apple documentation, a specific font size and font weight for the system font. You can always try the different kind of font weights to mimic the headline thickness.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM