Post

Replies

Boosts

Views

Activity

Reply to Problems with Swift Playgrounds
OK. I tried this: import SwiftUI public struct Block: View {     public var body: some View {         Rectangle()             .frame(width: 90, height: 90)     } } and in the ContentView: But now it gives me one other error. import PlaygroundSupport import SwiftUI struct ContentView: View {     var body: some View {         Block() // ERROR: 'Block' initializer is inaccessible due to 'internal' protection level.     } } PlaygroundPage.current.setLiveView(ContentView())
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Apr ’22
Reply to Attach magnetically an object in SwiftUI
Here's the code: import PlaygroundSupport import SwiftUI struct ContentView:  View {     @State private var isDragging = false     @State private var dragOffset: CGSize = .zero     @State var position: CGSize = .zero     @State private var hovered = false     var body: some View {         RoundedRectangle(cornerRadius: 20)             .foregroundColor(.red)             .frame(width: 100, height: 100)             .position(x: 400, y: 350)         RoundedRectangle(cornerRadius: 20)             .foregroundColor(.blue)             .frame(width: 100, height: 100)             .position(x: 400, y: 350)             .animation(.default, value: hovered)             .offset(x: dragOffset.width + position.width, y: dragOffset.height + position.height)             .gesture(                 DragGesture()                     .onChanged({ value in                         self.dragOffset = value.translation                     })                     .onEnded({ value in                         self.position.width += value.translation.width                         self.position.height += value.translation.height                         self.dragOffset = .zero                     })             )     } } PlaygroundPage.current.setLiveView(ContentView()) I want the blue square to attach with the red square when I drag near it.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Mar ’22
Reply to Show a badge on a Rectangle
I tried it but it shows me only the number and I wanted the badge icon, so a circle with a number on it. I tried this but the circle is very big how can I set the dimension of the circle so that it looks like a badge? struct ContentView: View {      func increment() {         count = count + 1     }     @State var showBadge = false     @State var count = 0     var body: some View {         Button(action: {             showBadge.toggle() // badge(9)             if showBadge { increment() }         }, label: {             Text("show badge")         })         if showBadge {             Rectangle()                 .frame(width: 180, height: 200)                 .foregroundColor(.blue)                 .position(x: 70, y: 70)                 .badge(count)                 .overlay(                     Circle(), alignment: .topLeading)         } else {             Rectangle()                 .frame(width: 180, height: 200)                 .foregroundColor(.blue)         }} }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’22
Reply to Add badge to an object
Here's my code: I want to show the badge on the badge on the rectangle each time I press on it. But currently it isn't working what I did wrong? import SwiftUI import PlaygroundSupport struct ContentView: View {     var body: some View {         Button(action: {             badge(9)          }, label: {             Rectangle()                 .frame(width: 180, height: 200)                 .foregroundColor(.blue)         })     } } PlaygroundPage.current.setLiveView(ContentView())
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’22
Reply to Shuffle randomly in SwiftUI
Okay, but the problem is where to locate them. I did something like this, but it gives errors. import SwiftUI import PlaygroundSupport struct ContentView: View {     var cards = [1, 2, 3, 4, 5, 6]     var body: some View {         cards.shuffle()         print(cards)     } } PlaygroundPage.current.setLiveView(ContentView())
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Feb ’22
Reply to Learn to code
Hi! When I started learn coding with Swift Playgrounds, I remember some levels were not easy to me, in fact I stayed on them many days. If you want to learn how code in Swift Playgrounds I recommend you the books about coding in Swift, you can find them in "Everyone Can Code" series on Apple Books and they're free. But they'll help you to get started and learn code not to pass levels. I hope it helped you.
Feb ’22
Reply to Neumorphic Button SwiftUI
I've seen it but it doesn't seem the answer of my question, maybe I explained my self not clearly. I want to create a button with the neumorphic animation.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
May ’22
Reply to How to put in casual position objects in SwiftUI
@Claude31 I have one more little question. If I would like to add more circle than 3, where should I edit the code?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Apr ’22
Reply to How to put in casual position objects in SwiftUI
@Claude31, it's right. But I want it without the animation, so display different circles in different positions but without the animation.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Apr ’22
Reply to Problems with Swift Playgrounds
OK. I tried this: import SwiftUI public struct Block: View {     public var body: some View {         Rectangle()             .frame(width: 90, height: 90)     } } and in the ContentView: But now it gives me one other error. import PlaygroundSupport import SwiftUI struct ContentView: View {     var body: some View {         Block() // ERROR: 'Block' initializer is inaccessible due to 'internal' protection level.     } } PlaygroundPage.current.setLiveView(ContentView())
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Apr ’22
Reply to Use fonts in SwiftUI
Sorry, I didn't express myself well... I need to change the text style and apply a font on it (like: Palatino, Gill Sans, Futura, SF Pro etc...). Is it possible?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Apr ’22
Reply to Use fonts in SwiftUI
@SpiderKenny actually I want to change the style of the text.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Apr ’22
Reply to Educational Supervisor’s Contact Information
Yeah, actually she's working in my school. So maybe it's OK.
Replies
Boosts
Views
Activity
Apr ’22
Reply to Attach magnetically an object in SwiftUI
I know @robnotyou, but nobody helped me.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Mar ’22
Reply to Attach magnetically an object in SwiftUI
Here's the code: import PlaygroundSupport import SwiftUI struct ContentView:  View {     @State private var isDragging = false     @State private var dragOffset: CGSize = .zero     @State var position: CGSize = .zero     @State private var hovered = false     var body: some View {         RoundedRectangle(cornerRadius: 20)             .foregroundColor(.red)             .frame(width: 100, height: 100)             .position(x: 400, y: 350)         RoundedRectangle(cornerRadius: 20)             .foregroundColor(.blue)             .frame(width: 100, height: 100)             .position(x: 400, y: 350)             .animation(.default, value: hovered)             .offset(x: dragOffset.width + position.width, y: dragOffset.height + position.height)             .gesture(                 DragGesture()                     .onChanged({ value in                         self.dragOffset = value.translation                     })                     .onEnded({ value in                         self.position.width += value.translation.width                         self.position.height += value.translation.height                         self.dragOffset = .zero                     })             )     } } PlaygroundPage.current.setLiveView(ContentView()) I want the blue square to attach with the red square when I drag near it.
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Mar ’22
Reply to Show a badge on a Rectangle
I tried it but it shows me only the number and I wanted the badge icon, so a circle with a number on it. I tried this but the circle is very big how can I set the dimension of the circle so that it looks like a badge? struct ContentView: View {      func increment() {         count = count + 1     }     @State var showBadge = false     @State var count = 0     var body: some View {         Button(action: {             showBadge.toggle() // badge(9)             if showBadge { increment() }         }, label: {             Text("show badge")         })         if showBadge {             Rectangle()                 .frame(width: 180, height: 200)                 .foregroundColor(.blue)                 .position(x: 70, y: 70)                 .badge(count)                 .overlay(                     Circle(), alignment: .topLeading)         } else {             Rectangle()                 .frame(width: 180, height: 200)                 .foregroundColor(.blue)         }} }
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’22
Reply to Add badge to an object
Here's my code: I want to show the badge on the badge on the rectangle each time I press on it. But currently it isn't working what I did wrong? import SwiftUI import PlaygroundSupport struct ContentView: View {     var body: some View {         Button(action: {             badge(9)          }, label: {             Rectangle()                 .frame(width: 180, height: 200)                 .foregroundColor(.blue)         })     } } PlaygroundPage.current.setLiveView(ContentView())
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’22
Reply to Shuffle randomly in SwiftUI
Okay, but the problem is where to locate them. I did something like this, but it gives errors. import SwiftUI import PlaygroundSupport struct ContentView: View {     var cards = [1, 2, 3, 4, 5, 6]     var body: some View {         cards.shuffle()         print(cards)     } } PlaygroundPage.current.setLiveView(ContentView())
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’22
Reply to Learn to code
Hi! When I started learn coding with Swift Playgrounds, I remember some levels were not easy to me, in fact I stayed on them many days. If you want to learn how code in Swift Playgrounds I recommend you the books about coding in Swift, you can find them in "Everyone Can Code" series on Apple Books and they're free. But they'll help you to get started and learn code not to pass levels. I hope it helped you.
Replies
Boosts
Views
Activity
Feb ’22
Reply to Change image with click
Okay thanks!
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’22
Reply to Need a little help with my code
And if I want to change the image from the current circle to a rectangle when I click the Right button. How can I do it if it's possible?
Topic: UI Frameworks SubTopic: SwiftUI Tags:
Replies
Boosts
Views
Activity
Feb ’22