我试图将HStack中的文本(图片中的Test
对齐到顶部,但是HStack对齐不起作用。它仍然在中心。
这是我的代码:
struct ContentView: View {
var body: some View {
VStack {
HStack(alignment: .top) {
Text("Test")
.font(.largeTitle)
.fontWeight(.bold)
.multilineTextAlignment(.leading)
Spacer()
}
.frame(width: 480, height: 160)
HStack {
Text(
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Neque volutpat ac tincidunt vitae semper quis lectus nulla at. Metus vulputate eu scelerisque felis imperdiet proin fermentum. Viverra accumsan in nisl nisi scelerisque. Aliquet sagittis id consectetur purus ut faucibus pulvinar elementum."
)
.font(.body)
.foregroundColor(Color.black)
.multilineTextAlignment(.leading)
.frame(
minWidth: 0, maxWidth: .infinity, minHeight: 0, maxHeight: .infinity,
alignment: .topLeading
)
.padding()
}
.frame(width: 480, height: 320)
.background(Color(.white))
}
.frame(width: 480, height: 480)
.background(
ZStack {
Rectangle()
.fill(
LinearGradient(
gradient: Gradient(colors: [.blue, .red]),
startPoint: .topLeading,
endPoint: .bottomTrailing
)
)
.blur(radius: 10)
VisualEffectView(
material: .toolTip,
blendingMode: .withinWindow
)
}
)
.mask(
RoundedRectangle(cornerRadius: 30)
)
}
}
答案 0 :(得分:2)
您需要在框架中添加对齐方式
{{1}}