I am new to swift, so thanks for all the help… I am working on my first app and this works great if my button is press it goes into the didTap function.. But I need to do something else if its a LONG HOLD on the button…
Being new to this I need some help please… Here is more of the code so you can understand my coding, style,
As of right now NONE of the examples worked
var body: some View {
ZStack(alignment: .bottom) {
Color.black.ignoresSafeArea()
VStack {
HStack {
Spacer()
Text(currentValue)
.foregroundColor(.white)
.font(.system(size: 72))
}
.padding()
ForEach(buttons, id: .self) { row in
HStack {
ForEach(row, id: .self) { button in
Button {
buttonTapped(button: button)
} label: {
HStack {
Text(button.rawValue)
.foregroundColor(button.foregroundColor)
.font(.system(size: 30, weight: .semibold))
.frame(width: button.getButtonWidth(), height: button.getButtonWidth())
if(button.isZeroButton) {
Spacer()
}
}
.frame(width: button.width, height: button.height)
.background(button.backgroundColor)
.cornerRadius(button.height)
}
}
}
}
}
.padding(.bottom)
}
}
2
Answers
We use
onTapGesture
for tap actions, andonLongPressGesture
for long press actions:you could just use
Text
instead of aButton
, such as: