我在一个视图中有这段代码:
struct TextFieldClearButton: ViewModifier {
@Binding var text: String
func body(content: Content) -> some View {
HStack {
content
if !text.isEmpty {
Button(
action: { self.text = "" },
label: {
Image(systemName: "delete.left")
.foregroundColor(Color(UIColor.opaqueSeparator))
}
)
}
}
}
}
我遇到了两个错误:
Type 'TextFieldClearButton' does not conform to protocol 'ViewModifier'
(类型“TextFieldClearButton”不符合协议“ViewModifier”)Static method 'buildBlock' requires that 'Content' conform to 'View'
(静态方法“buildBlock”要求“Content”符合“View”)
看起来我根本不能使用
ViewModifier
。 添加非常简单的情况也会出错吗??请参考以下图片: