NavigationBarTitle doesn't shrink text with minimumScaleFactor() or allowsTightening()

Viewed 92

When using .navigationBarTitle on a NavigationView, adding the modifiers .minimumScaleFactor(0.5) or .allowsTightening(true) has no effect. The text is still cut off and remains same size.

My app displays a reference code and a few other bits of information in the navigation bar title and it fits perfectly on Plus sized iPhones but gets trimmed (...) on the smaller screen ones. This information is quite vital to the operation of the app and we are already short of screen space so really don't have anywhere else to put this info.

With UIKit, I would have created a special TitleView to replace the title text in the NavigationBar, but that doesn't work in SwiftUI.

Is there any workaround for this?

Example:

struct ContentView: View {
  let items = ["Chocolate", "Vanilla", "Strawberry", "Mint Chip",
               "Pistachio"]
  let title = "A long title that doesn't fit on a standard iPhone"
  var body: some View {
    NavigationView {
      List(items, id: \.self) {
        Text($0)
      }
      .navigationBarTitle(title, displayMode: .inline).minimumScaleFactor(0.5).allowsTightening(true)
    }
  }
}

ScreenShot from iPhone 8 Plus: ScreenShot from iPhone 8 Plus

Screenshot from iPhone 8: Screenshot from iPhone 8

0 Answers
Related