Stepper: how to make label font as large as possible?

Imagine a Stepper with a left label (from troz.net):


Stepper(value: $stepperValue, in: 0...20) {
    Text("Value in child = \(stepperValue)")
        .font(.headline)
        .fontWeight(.medium)
        .multilineTextAlignment(.leading)
        //.minimumScaleFactor(0.50)
}

The label could change or be a different language. What I tried (unsuccessfully) to do in the last line is have the label fit as large a rect as the Stepper could allow. but when I uncomment the minimumScaleFactor line, the text shrinks immediately to that size.


How can I get the labe lto scale so the full horizonal space (with readable padding) is consumed?

Replies

I tried this:


struct ContentView: View {
    @State var stepperValue: Int
    var body: some View {
        Stepper(value: $stepperValue, in: 0...20) {
            Text("Value in child = \(stepperValue)")
                .font(.largeTitle)
                .fontWeight(.medium)
                .multilineTextAlignment(.leading)
                .minimumScaleFactor(0.50)
        }
    }
}

Then I get a very large font.


I changed text to a longer one

          Text("Value in child with a longer text = \(stepperValue)")

The text remained same size on 2 lines.


Adding a frame modifier:

        Stepper(value: $stepperValue, in: 0...20) {
            Text("Value in child with long text = \(stepperValue)")
                .font(.largeTitle)
                .fontWeight(.medium)
                .multilineTextAlignment(.leading)
                .minimumScaleFactor(0.50)
                .frame(width:300, height: 40, alignment: .topLeading)
        }



gives a smaller size with the long text

and gives a large size with the shorter text.

It just seems I can do better with my own Text() view in a HStack, but haven't tried. The Stepper could be shown in an iPad with a huge amount of space, or in a small iPhone, so no easy way to apply a frame to it. It sure seems odd to me that the text size shrinks with the minimumScaleFactor regardless of the number of characters.