gpt4 book ai didi

ios - SwiftUI 披露组文本对齐

转载 作者:行者123 更新时间:2023-12-05 04:25:40 31 4
gpt4 key购买 nike

有没有办法防止 DisclouseGroup 标题中的换行文本居中对齐?

Disclosure group with center aligned text

我尝试添加以下内容,但两种方法都没有效果:

DisclosureGroup("A really long disclosure group title that is being center aligned.", isExpanded: false) {
...
}
.multilineTextAlignment(.leading)
DisclosureGroup("A really long disclosure group title that is being center aligned.", isExpanded: false) {
...
}
.frame(maxWidth: .infinity, alignment: .leading)

最佳答案

您可以使用 DisclosureGroup 的标签初始化器。您可以阅读更多相关信息 here

这是一个工作示例。

struct ContentView: View {

@State private var isExpanded = false
var body: some View {
VStack {
DisclosureGroup(isExpanded: $isExpanded) {
Text("This is some text")
} label: {
Text("A really long disclosure group title that is being center aligned.")
.multilineTextAlignment(.leading)
}

}
}
}

这给出了以下输出

enter image description here

已测试 Xcode 14 beta 4 iOS 16 模拟器

关于ios - SwiftUI 披露组文本对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73186462/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com