首页 > 解决方案 > lineLimit in View does not work in SwiftUI

问题描述

The text inside my chatbubbles won't break in new line.

Here's the "chatbubble" extracted in an own view

struct chatPartnerBubble: View {
    var textMsg: String
    var body: some View {
        VStack(alignment: .leading) {
            HStack {
                HStack {
                    Text(textMsg)
                        .foregroundColor(Color.white)
                        .padding(10)
                        .lineLimit(nil)
                }
                .background(Color.blue)
                .cornerRadius(12)
                Spacer()
            }.padding(.leading)
        }
    }
}

and here is the ChatView

ScrollView {
            VStack {
                chatPartnerBubble(textMsg: "text")
                chatPartnerBubble(textMsg: "text")
                chatPartnerBubble(textMsg: "text")
                chatPartnerBubble(textMsg: "text")
                chatPartnerBubble(textMsg: "text")
                chatPartnerBubble(textMsg: "text")
            }
        }

But if the textMsg is longer, it just dots..., and does not break into new line

标签: swiftui

解决方案


我似乎工作得很好,我使用的是 Xcode 11.2 Beta 2,所以 Xcode 版本可能是问题所在。我记得我以前遇到过类似的问题,解决方案VStack(alignment: .center, spacing: 0)可能有帮助

在此处输入图像描述


推荐阅读