如何更改 SwiftUI 中按钮的背景颜色?
How can I change background color of button in SwiftUI?
在 SwiftUI 中更改按钮背景颜色的最佳方法是什么?
我想创建一个图块,它是一个带有居中文本和某种颜色的矩形背景的按钮。
Button(action: { }) {
Text("Button Text!").padding()
}
.background(Color.black)
Button(action: {self.buttonTapped()}) {
Text("Button")
.padding(.all, 12)
.foregroundColor(.white)
.background(Color.red)
}
这就是整个背景可以点击的方式
您可以在没有任何容器的情况下直接向按钮添加修改(例如:群组)
Button(action: {}) {
Text("Click me!")
}
.padding()
.foregroundColor(.white)
.background(Color.red)
希望能帮到人!
SwiftUI 颜色
从 iOS v13 及更高版本开始,当您使用颜色时,您应该考虑明暗模式。
.foregroundColor(.red)
.background(.blue)
例如.black在深色模式下是不可见的(black on black)。您可以使用系统颜色作为变体。例如UIColor.label
在 SwiftUI 中更改按钮背景颜色的最佳方法是什么?
我想创建一个图块,它是一个带有居中文本和某种颜色的矩形背景的按钮。
Button(action: { }) {
Text("Button Text!").padding()
}
.background(Color.black)
Button(action: {self.buttonTapped()}) {
Text("Button")
.padding(.all, 12)
.foregroundColor(.white)
.background(Color.red)
}
这就是整个背景可以点击的方式
您可以在没有任何容器的情况下直接向按钮添加修改(例如:群组)
Button(action: {}) {
Text("Click me!")
}
.padding()
.foregroundColor(.white)
.background(Color.red)
希望能帮到人!
SwiftUI 颜色
从 iOS v13 及更高版本开始,当您使用颜色时,您应该考虑明暗模式。
.foregroundColor(.red)
.background(.blue)
例如.black在深色模式下是不可见的(black on black)。您可以使用系统颜色作为变体。例如UIColor.label