SwiftUI - IOS 15 - Text .mimimumScaleFactor - always being applied
Asked Answered
A

2

5

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.

Athwart answered 26/9, 2021 at 13:15 Comment(6)
Provided code snapshot works fine here. Xcode 13 / iOS 15Telles
Hi @Telles - so you are getting a text string that fits the screen edge to edge? For me, even a small screen is being scaled down and not filling the width as it does in ios 14.Athwart
I noticed the same thing in one of my apps. Since iOS 15, the text gets scaled incorrectly. Didn't change anything in code. Any solution yet...?Thessalonians
I'm afriad not @Thessalonians - its seems to only happen on a couple of screen sizes and in my app just looks lightly wrong and doesn't actually break any functionality. If I find a solution I'll report back here.Athwart
I may have finally found a solution to this problem. Check out my latest answer. Does it work for you?Thessalonians
@Thessalonians sorry for the slow response. Yes it does! Works perfectly, thanks!Athwart
T
5

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:)

Thessalonians answered 9/10, 2021 at 7:17 Comment(0)
D
2

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. 😔

Destructive answered 21/3, 2022 at 16:35 Comment(1)
I agree its unnerving! I've just tried you way in my app and can confirm it works! Thanks.Athwart

© 2022 - 2025 — McMap. All rights reserved.