我试图在 Text 结构内的文本上设置对齐方式,但我找不到任何这样做的属性。代码示例(更新):
VStack(alignment: .center) {
Text(optionItem.title)
.fontWeight(.heavy)
.color(optionItem.color)
.font(.system(size: 64))
.frame(width: bounds.width, height: 100, alignment: .center)
.padding(.top, 60)
Text(optionItem.description)
.lineLimit(nil)
.padding([.leading, .trailing], 40)
.frame(width: bounds.width, height: 120, alignment: .center)
.font(.system(size: 16))
}
.padding(.bottom, bounds.height * 0.55)
Run Code Online (Sandbox Code Playgroud)
文本“对象”居中,但不是里面的文本。图片: