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

mysterious unwanted space got added in Text view

It’s simpler to just read the code and see the end result in the image, my question is why is Actuation Force and Bottom-out Force not aligned with the text views above them? In Actuation Force text view, there seems to be some mysterious padding added to its left while Bottom-out Force does not have it?

enter image description here

VStack {
    VStack {
        HStack {
            VStack(alignment: .leading, spacing: 5) {
                Text("**Pre-travel Distance**")
                Text("how far down the key must be pressed for it to actuate")
            }
            .frame(width: 250)
            .background(.red)
            SwitchPropertyCircularView(upperBoundValue: theSwitch.preTravelDistance!, unit: "mm")
        }
        .background(.blue)

        HStack {
            VStack(alignment: .leading, spacing: 5) {
                Text("**Total Travel Distance**")
                Text("how far down the key must be pressed for it to bottom out")
            }
            .frame(width: 250)
            .background(.red)
            SwitchPropertyCircularView(upperBoundValue: theSwitch.totalTravelDistance!, unit: "mm")
        }
        .background(.blue)
    }
    .frame(width: 380)
    .background(Color.gray)

    VStack {
        HStack {
            VStack(alignment: .leading, spacing: 5) {
                Text("**Actuation Force**")
                Text("the force needed to register a keypress")
            }
            .frame(width: 250)
            .background(.red)
            SwitchPropertyCircularView(upperBoundValue: Double(theSwitch.actuationForce!), unit: "gf")
        }
        .background(.blue)

        HStack {
            VStack(alignment: .leading, spacing: 5) {
                Text("**Bottom-out Force**")
                Text("the force needed for a switch to bottom out")
            }
            .frame(width: 250)
            .background(.red)
            SwitchPropertyCircularView(upperBoundValue: Double(theSwitch.bottomOutForce!), unit: "gf")
        }
        .background(.blue)
    }
    .frame(width: 380)
    .background(Color.gray)
}

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

>Solution :

On "Bottom-out Force," it looks like the first line is wide enough before it wraps words that it pushes the Text width to the maximum width of the view. On the others, it gets wrapped with shorter line lengths, and then ends up adding padding to center the text within the view.

You can fix this by adding a .leading alignment to your VStack. For example:

VStack(alignment: .leading, spacing: 5) {
  Text("**Actuation Force**")
  Text("the force needed to register a keypress")
}
.frame(width: 250, alignment: .leading) //<-- Here

Repeat for each VStack that shares the same qualities.

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