如何在 WatchOS 中使用背景视图填充整个 Button 区域? [英] How do you fill entire Button area with background View in WatchOS?
本文介绍了如何在 WatchOS 中使用背景视图填充整个 Button 区域?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图让我的背景视图跨越 Apple Watch 外形尺寸上按钮的整个区域.
I am trying to have my background view span the entire area of a Button on an Apple Watch form factor.
struct SurveyView: View {
var body: some View {
Button(action: {
print("Test tapped.")
}) {
HStack {
Text("Test")
.fontWeight(.semibold)
}
.frame(minWidth: 0, maxWidth: .infinity)
.padding()
.foregroundColor(.white)
.background(LinearGradient(gradient: Gradient(colors: [.green, .blue]), startPoint: .leading, endPoint: .trailing))
}
}
}
如何让背景跨越整个按钮?
How can I make the background span the entire Button?
更新:原来我的问题也与处于列表视图中有关.设置面具并不能完全解决它.
Update: Turns out my issue is also related to being in a List View. Setting a mask doesn't quite solve it.
struct SurveyView: View {
var body: some View {
List() {
Button(action: {
print("Test tapped.")
}) {
Text("Test")
.fontWeight(.semibold)
}
.background(Color.orange)
.mask(RoundedRectangle(cornerRadius: 24))
}
}
}
推荐答案
我会这样做:
Button(action: {
print("Test tapped.")
}) {
Text("Test")
.fontWeight(.semibold)
.padding()
.foregroundColor(.white)
}
.background(LinearGradient(gradient: Gradient(colors: [.green, .blue]), startPoint: .leading, endPoint: .trailing))
.mask(RoundedRectangle(cornerRadius: 24))
更新:列表的情况
var body: some View {
List() {
Button(action: {
print("Test tapped.")
}) {
Text("Test")
.fontWeight(.semibold)
.padding()
}
.background(Color.orange)
.mask(RoundedRectangle(cornerRadius: 24))
.listRowPlatterColor(Color.clear)
}
}
这篇关于如何在 WatchOS 中使用背景视图填充整个 Button 区域?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文