@Claude31 I have one more little question. If I would like to add more circle than 3, where should I edit the code?
Post
Replies
Boosts
Views
Activity
@Claude31, it's right. But I want it without the animation, so display different circles in different positions but without the animation.
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())
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?
@SpiderKenny actually I want to change the style of the text.
I know @robnotyou, but nobody helped me.
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.
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)
}}
}
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())
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())
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.
Okay thanks!
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?
But here it's asking me to report an issue, but mine isn't an issue it's only a software feedback. How can I do?
OK, for using Metal I have to install an app? And can I use them also on Mac’s Swift PlaygroundS?