As you can see from the sample code below, I tried to filter the views (one circle or two circles) depending on the index number.
Easily can be found that the single views are at 0 , 3, 6, etc and the doubles are at 1,5,7 etc and 2,4,6.
As you can see you can get easily the single views, but although I made an HStack for the two circle view, they appear as separate..
maybe you can work around something...
struct ContentView: View {
let array = ["☺️", "😟" , "😡", "🐵" , "🐼", "🐹", "🪱" , "🦋", "🐝"]
// Positions 0 1 2 3 4 5 6 7 8
var body: some View {
VStack {
ForEach(array, id:\.self) { text in
if array.firstIndex(where: {$0 == text }) == 0 || array.firstIndex(where: {$0 == text })!.isMultiple(of: 3) {
CircleView(text: text)
}
else {
HStack {
if let x = array.firstIndex(where: {$0 == text }) {
if (x % 2 == 0) {
CircleView(text: array[x])
}
}
if let y = array.firstIndex(where: {$0 == text }) {
if (y % 2 == 1) {
CircleView(text: array[y])
}
}
}
}
}
}
}
}
struct CircleView: View {
var text = "A"
var body: some View {
ZStack {
Circle().strokeBorder(lineWidth: 10).foregroundColor(.blue).frame(width: 100, height: 100)
Text(text).font(.largeTitle)
}
}
}