Hey there! I have a Circle, and I would like to create many on this circle and display them in random position on the screen. Is it possible?
Thanks in advance.
What do you mean without animation ? Without the button action ?
Then just do this:
struct ContentView: View {
@State var xPos: [CGFloat] = [CGFloat.random(in: 50...300), CGFloat.random(in: 50...300), CGFloat.random(in: 50...300)]
@State var yPos: [CGFloat] = [CGFloat.random(in: 50...500), CGFloat.random(in: 50...500), CGFloat.random(in: 50...500)]
let colors: [Color] = [.red, .green, .blue]
var body: some View {
GeometryReader { geometry in
ForEach ((0..<xPos.count), id: \.self) {
Circle()
.foregroundColor(colors[$0])
.frame(width: 80, height: 80)
.position(x: xPos[$0], y: yPos[$0])
}
}
}
}
.
create many on this circle and display them in random position
Do you mean inside the large circle ? On the border of it ?