SwiftUI - IOS 15 - Text .mimimumScaleFactor - always being applied

803 Views Asked by At

Can't find any documentation of this issue.

One of my apps has a text view with a .minimumScaleFactor(0.5). This works perfectly in iOS 14.0.* - when the text would be wider than the view its scales nicely to fit - IE filling the full width of the screen.

Unfortunatly, in iOS 15 the .minimumScaleFactor seems to be being applied regardless of the size of the content. Strings that would require no scaling to fit are being scaled down.

Is this an undocumented change? Is there a new way to handle this that I am unaware of?

Code is below:

var body: some View {

    VStack() {

        HStack() {

            Text(supplier.name ?? "Unknown Supplier")
                .font(.title)
                .lineLimit(1)
                .allowsTightening(true)
                .minimumScaleFactor(0.5)

            Button(action: {}) {

            Image(systemName: "star.fill")
                .imageScale(.large)

            }

        }

    }

}

Any help would be greatly appretiated.

EDIT - this seems to only be an issue on certain iphones - initial test on iPhone SE (2nd generation) iOS 15.

2

There are 2 best solutions below

0
On BEST ANSWER

Setting the view as fixed using .fixedSize worked for me.

In your case:

  Text(supplier.name ?? "Unknown Supplier")
            .font(.title)
            .fixedSize(horizontal: false, vertical: true)
            .lineLimit(1)
            .allowsTightening(true)
            .minimumScaleFactor(0.5)

Docs: https://developer.apple.com/documentation/swiftui/menu/fixedsize(horizontal:vertical:)

1
On

In my case, the behavior was rooted in the wrapper view. Once I forced it to occupy all the remaining horizontal space, the inner (auto-shrinking) text started to work as expected.

HStack {
    VStack {
        Text("Big")
            .lineLimit(1)
            .minimumScaleFactor(0.01)
        Text("Small")
    }
}
    .frame(maxWidth: .infinity) // 

Still, it is kind of unnerving that the same code works differently on various iOS runtimes.