【问题标题】:Why text gets cutoff in Text in SwiftUI为什么文本在 SwiftUI 中的文本中被截断
【发布时间】:2022-01-24 04:17:06
【问题描述】:

从下面的图片中可以看到L(Lorem)和p(预览版)被截断,知道为什么Text 内的某些文本会被截断吗?

struct ContentView: View {
    var body: some View {
        ZStack {
            Image("placeholder-image")
                .resizable()
                .scaledToFill()
                .ignoresSafeArea()

            VStack {
                Text("Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups..")
                    .foregroundColor(Color.systemGray)
                    .cornerRadius(15)

                Button("Tap Me") {
                    // some action
                }.buttonStyle(.borderedProminent)
            }
            .padding()
            .background(.thinMaterial)
            .cornerRadius(15)
        }
    }
}

【问题讨论】:

    标签: swiftui


    【解决方案1】:

    你可以使用如下文本:

      .fixedSize(horizontal: false, vertical: true)
    

    【讨论】:

    • 很遗憾,将 .fixedSize(horizontal: false, vertical: true) 添加到 Text 视图中不起作用。谢谢。
    • 你可以给VStack.frame(width: 200)
    【解决方案2】:

    cornerRadius 添加了剪辑,因此在文本之后将其删除(无论如何,您的代码逻辑不需要它,即使它的行为会有所不同)

    VStack {
        Text("Lorem ipsum is placeholder text commonly used in the graphic, print, and publishing industries for previewing layouts and visual mockups..")
            .foregroundColor(Color.systemGray)
            //.cornerRadius(15)                  // << this !!
    

    【讨论】:

    • 天啊,我错过了显而易见的事情。谢谢!
    猜你喜欢
    • 1970-01-01
    • 2020-04-18
    • 2020-01-08
    • 1970-01-01
    • 1970-01-01
    • 2015-02-08
    • 1970-01-01
    • 1970-01-01
    • 2010-12-05
    相关资源
    最近更新 更多