【发布时间】:2019-10-07 11:53:11
【问题描述】:
我正在努力删除 SwiftUI 中自定义圆形按钮元素的背景,其定义如下:
struct NavButton: View {
var body: some View {
Button(action: {})
VStack {
Text("Button")
}
.padding(40)
.background(Color.red)
.font(.title)
.mask(Circle())
}
}
}
这会导致按钮周围出现矩形浅灰色背景,我希望它不显示:
我尝试在按钮上附加一个“背景”修饰符,它表现出非常奇怪的行为:如果它设置为“Color.clear”,则没有效果。但如果我将它设置为“Color.green”,它确实会按预期改变背景。
将“Background”修饰符设置为“Color.green”的示例:
struct NavButton: View {
var body: some View {
Button(action: {})
VStack {
Text("Button")
}
.padding(40)
.background(Color.red)
.font(.title)
.mask(Circle())
}
.background(Color.green) // has no effect if set to "Color.clear"
}
}
我想知道我是否在这里遗漏了什么?
PS:我使用的是 Xcode 11.1 (11A1027)
【问题讨论】:
-
尝试调整按钮的框架以适应圆形大小,而不是隐藏按钮的背景颜色。
标签: ios swift watchkit swiftui