我有一个按钮
struct ContentView : View {
var body: some View {
HStack {
Button(action: {}) {
Text("MyButton")
.color(.white)
.font(Font.system(size: 17))
}
.frame(height: 56)
.background(Color.red, cornerRadius: 0)
}
}
}
但我想将它固定在superview的边缘上(trailing与superview的trailing和leading对齐),就像这样:
HStack
对我没有帮助,而且它需要一个固定的frame
或者宽度等于UIScree.size
都不是灵活的解决方案。
.padding(.horizontal, 20)
,如果你想要两侧都有填充,而不必单独提及左右。 - perte