我用以下代码创建了一个圆形按钮:
struct RoundButton : View {
var value = "..."
var body: some View {
GeometryReader { geometry in
Button(action: {}) {
VStack {
Text(self.value)
.font(.headline)
.color(Color("NightlyDark"))
Text("MIN")
.font(.footnote)
.color(.white)
}
.frame(width: geometry.size.width, height: geometry.size.height)
}
.clipShape(Circle())
}
}
}
但是,单击按钮时,形状会变形。知道为什么会这样吗?
当我使用时也会发生同样的情况 .mask(Circle())
这是测试版内容还是正常行为?有谁知道创建圆形按钮的更好方法吗?
Button
默认情况下,这里发生的是将所有屏幕[宽+高]视为其框架。
所以你必须设置Button
也。
我认为这是 watchOS
这是您的代码:
struct RoundButton: View {
var value = "..."
var body: some View {
GeometryReader { geometry in
Button(action: {}) {
VStack {
Text(self.value)
.font(.headline)
.foregroundColor(Color("NightlyDark"))
Text("MIN")
.font(.footnote)
.foregroundColor(.white)
}
.frame(width: geometry.size.width, height: geometry.size.height)
}
.frame(width: geometry.size.width, height: geometry.size.height)
.clipShape(Circle())
}
}
}
注意:我正在使用Xcode 11 Beta 4
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句