Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does Spacer() not work? (between Text and Stepper)

Why does my Spacer() between Text and Stepper not work in the code below?

Here is how it looks like:

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here is how I would like it to look like:

enter image description here

import SwiftUI

struct FontEditView: View {
    @Binding var fontSize: CGFloat
    
    var body: some View {
        NavigationStack {
            Form {
                HStack {
                    Text("Font Size")
                    Spacer()
                    Stepper(fontSize.formatted(), value: $fontSize, in: 5...50)
                }    
            }
        }
    }
}

struct FontEditView_Previews: PreviewProvider {
    static var previews: some View {
        FontEditView(fontSize: .constant(20))
    }
}

>Solution :

Just add .fixedSize() to the Stepper

Fixes this view at its ideal size.

Stepper(fontSize.formatted(), value: $fontSize, in: 5...50)
    .fixedSize()
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading