NEW: Start my new Ultimate Portfolio App course with a free Hacking with Swift+ trial! >>

SwiftUI wrapping text mid-word

Forums > SwiftUI

Hello,

I'm working on a SwiftUI project with cards that contain text. However, swiftUI will sometimes cutoff the text mid-word and put a single (or a few) letters on a new line. I want to prevent words from being cutoff mid-line, but can't figure out how to do so.

I would appreciate any thoughts on how to prevent the text from wrapping when I don't want it to.

var body: some View {
        VStack (alignment: .center){
            HStack {
                Spacer()
                VStack {
                    Spacer()
                    Text(card.text.uppercased())
                            .font(.largeTitle)
                            .minimumScaleFactor(0.5)
                            .foregroundColor(Colors.shared.questionText)
                            .multilineTextAlignment(.center)
                            .lineLimit(4)
                            .allowsTightening(true)
                    //.padding(.horizontal, 3)
                    Spacer()
                    Text(card.emojis)
                        .font(.system(size: 54))
                        .minimumScaleFactor(0.5)
                        .multilineTextAlignment(.center)
                        .lineLimit(1)
                        .allowsTightening(true)
                    //.padding(.horizontal, 3)
                    Spacer()
                    Text(card.examples)
                        .minimumScaleFactor(0.5)
                        .foregroundColor(Colors.shared.exampleText)
                        .multilineTextAlignment(.center)
                        .lineLimit(2)
                        .allowsTightening(true)
                    //.padding(.horizontal, 5)
                    Spacer()
                }
                Spacer()

            }
        }
        .padding(.horizontal, 2)
        .background(
            RoundedRectangle(cornerRadius: 15)
                .foregroundColor(Colors.shared.cardBackground)
                .shadow(radius: 2)
        )
        .opacity(1)

   

I know it's not much help, but if it makes you feel any better at all I can tell you that I, too, have been unsuccessfully dealing with this problem for a year now.

I can't seem to stop Springsteen or Millenium from displaying as Springste / en or Milleni / um on two lines, regardless of how I change the modifiers. It's awful.

   

Hacking with Swift is sponsored by Instabug

SPONSORED Catch bugs as soon as they happen and know exactly why a crash occurred. Instabug's SDK grabs all the logs they need to fix bugs, crashes and performance issues in minutes instead of days. Get screenshots, device details, network logs, repro steps, and tons of other critical insights needed to resolve issues and prioritize product backlogs straight from your dashboard. It only takes a minute to integrate!

Get started now

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.