Hello I am trying to achieve simple functionality but somehow I am unable to use action of button, it never triggered, and not only in this code but also in my entire application, Am I doing something wrong or is it a glitch from SwiftUI. But onTapGesture works perfectly.
struct CounterView: View {
@State var counter = 0
var body: some View{
HStack(alignment: .center, spacing: 8){
Button(action: {
//self.counter += 1
}) {
HStack {
Image(systemName: "plus")
}.padding(4.0)
.overlay(
RoundedRectangle(cornerRadius: 4.0)
.stroke(lineWidth: 1.0)
.trim()
)
.onTapGesture {
self.counter += 1
}
}}}
Help me resolve this issue.
You need to set a size on the image
Image(systemName: "plus")
.font(.system(size: 40, weight: .regular))
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.