Post

Replies

Boosts

Views

Activity

Change image with click
Hi there! I want to change the current circle to a rectangle when I press the Right button. Is it possible if yes how can I it? Here's the code: struct ContentView: View { @State var vOffset: CGFloat = 0 @State var hOffset: CGFloat = 0 var body: some View { Circle() .frame(width: 80, height: 80) .position(x: 140 + hOffset, y: 140 + vOffset) Spacer(minLength: 20) Button( action: { vOffset += 20 }, label: { Image(systemName: "arrowtriangle.down.circle.fill") .resizable() .foregroundColor(.blue) .frame(width: 70, height: 70) .padding() } ) Button( action: { hOffset += 20 }, label: { Image(systemName: "arrowtriangle.right.circle.fill") .resizable() .foregroundColor(.blue) .frame(width: 70, height: 70) .padding() } ) } }
2
0
891
Feb ’22
Change image with click
Hi there! I want to change the current circle to a rectangle when I press the Right button. Is it possible if yes how can I it? Code: struct ContentView: View { @State var vOffset: CGFloat = 0 @State var hOffset: CGFloat = 0 var body: some View { Circle() .frame(width: 80, height: 80) .position(x: 140 + hOffset, y: 140 + vOffset) Spacer(minLength: 20) Button( action: { vOffset += 20 }, label: { Image(systemName: "arrowtriangle.down.circle.fill") .resizable() .foregroundColor(.blue) .frame(width: 70, height: 70) .padding() } ) Button( action: { hOffset += 20 }, label: { Image(systemName: "arrowtriangle.right.circle.fill") .resizable() .foregroundColor(.blue) .frame(width: 70, height: 70) .padding() } ) } } Thanks.
0
0
434
Feb ’22
Need a little help with my code
Hello everyone, Can someone tell me how to move the circle in the same position of the arrow (like to go up if I press up, down if I press down... and so right if I press right) but it doesn't go right, I can't know why. Please can someone help me to figure out this? Here's the code: import SwiftUI import PlaygroundSupport struct ContentView: View {     @State var offset: CGFloat = 0     var body: some View {         Circle()             .frame(width: 80, height: 80)             .position(x: 140, y: 140 + offset)         Spacer(minLength: 20)         Button(             action: {                 offset += 20                          }, label: {                 Image(systemName: "arrowtriangle.down.circle.fill")                     .resizable()                     .foregroundColor(.blue)                     .frame(width: 70, height: 70)                     .padding()             }         )         Button(             action: {                 offset += 20                      }, label: {                 Image(systemName: "arrowtriangle.right.circle.fill")                     .resizable()                     .foregroundColor(.blue)                     .frame(width: 70, height: 70)                     .padding()             }         )     } } PlaygroundPage.current.setLiveView(ContentView()) Thanks in advance.
2
0
423
Feb ’22
Move the circle according the arrow
Hello everyone, Can someone tell me how to move the circle in the same position of the arrow (like to go up if I press up, down if I press down... and so right if I press right) but it doesn't go right, I can't know why. Please can someone help me to figure out this? Here's the code: import SwiftUI import PlaygroundSupport struct ContentView: View {     @State var offset: CGFloat = 0     var body: some View {         Circle()             .frame(width: 80, height: 80)             .position(x: 140, y: 140 + offset)         Spacer(minLength: 20)         Button(             action: {                 offset += 20                          }, label: {                 Image(systemName: "arrowtriangle.down.circle.fill")                     .resizable()                     .foregroundColor(.blue)                     .frame(width: 70, height: 70)                     .padding()             }         )         Button(             action: {                 offset += 20                      }, label: {                 Image(systemName: "arrowtriangle.right.circle.fill")                     .resizable()                     .foregroundColor(.blue)                     .frame(width: 70, height: 70)                     .padding()             }         )     } } PlaygroundPage.current.setLiveView(ContentView()) Thanks in advance.
0
0
517
Feb ’22
Move according to the button
Hello there! I would like to move the object according to the button press. In this code, I have the circle and I like to move it down if I press the down button. Can anyone tell me how can I do this? Thanks. import SwiftUI import PlaygroundSupport struct ContentView: View {     var body: some View {         Circle()             .frame(width: 80, height: 80)         Spacer(minLength: 20)             Button{             } label: {                 Image(systemName: "arrowtriangle.down.circle.fill")                     .resizable()                     .foregroundColor(.blue)                     .frame(width: 70, height: 70)                     .padding()             }     } } PlaygroundPage.current.setLiveView(ContentView())
1
0
1.1k
Feb ’22