【问题标题】:Clip text in DisclosureGroup在 DisclosureGroup 中剪辑文本
【发布时间】:2021-08-14 11:20:52
【问题描述】:

我有一个DisclosureGroup,如果它太长,我想剪掉Text 标签,而不是。我怎样才能做到这一点?

当前代码:

struct ContentView: View {
    var body: some View {
        List {
            DisclosureGroup {
                Text("Content")
            } label: {
                Text("Some long label which is too long for the screen")
                    .lineLimit(1)
                    .fixedSize(horizontal: true, vertical: false)
                    // Would likely clip to bounds here, etc...
            }
        }
        .listStyle(.sidebar)
    }
}

此尝试的问题是披露指示箭头现在不在屏幕上。我希望宽度保持不变,但只是剪裁 Text 而不是截断它。

Without fixedSize With fixedSize

预期(粗略编辑):

【问题讨论】:

  • 您的预期结果是什么?
  • 你试过这个.minimumScaleFactor(0.5)吗?
  • @RajaKishan 我添加了预期结果的图像。我不想缩小文本 - 相反我会在最后淡出它(昨天的post

标签: swift swiftui swiftui-list


【解决方案1】:

使用overlay 有效。

代码:

struct ContentView: View {
    var body: some View {
        List {
            DisclosureGroup {
                Text("Content")
            } label: {
                Color.clear
                    .overlay(alignment: .leading) {
                        Text("Some long label which is too long for the screen")
                            .lineLimit(1)
                            .fixedSize(horizontal: true, vertical: false)
                    }
                    .clipped()
            }
        }
        .listStyle(.sidebar)
    }
}

结果:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-23
    • 2015-12-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多