//Need to create a random Array of 18 x 8 buttons with max 8 buttons with the same color of
//the 18 and no redundant color in a row⦠Stuck on getting the random string values into the
// Array back - Any Ideas ? Iβm on day 2 of CWC+
import SwiftUI
enum ChromaButton:String {
case a1 = β1β
case b1 = β2β
case c1 = β3β
case d1 = β4β
case e1 = β5β
case f1 = β6β
case g1 = β7β
case h1 = β8β
case i1 = β9β
case j1 = β10β
case k1 = β11β
case l1 = β12β
case m1 = β13β
case n1 = β14β
case o1 = β15β
case p1 = β16β
case q1 = β17β
case r1 = β18β
var buttonColor: Color {
switch self {
case .a1:
return Color(UIColor(red: 255/255, green: 0/255, blue: 255/255, alpha: 1))
case .b1:
return Color(UIColor(red: 190/255, green: 2/255, blue: 255/255, alpha: 1))
case .c1:
return Color(UIColor(red: 125/255, green: 1/255, blue: 255/255, alpha: 1))
case .d1:
return Color(UIColor(red: 22/255, green: 0/255, blue: 255/255, alpha: 1))
case .e1:
return Color(UIColor(red: 0/255, green: 125/255, blue: 255/255, alpha: 1))
case .f1:
return Color(UIColor(red: 0/255, green: 190/255, blue: 255/255, alpha: 1))
case .g1:
return Color(UIColor(red: 0/255, green: 255/255, blue: 255/255, alpha: 1))
case .h1:
return Color(UIColor(red: 0/255, green: 252/255, blue: 187/255, alpha: 1))
case .i1:
return Color(UIColor(red: 2/255, green: 255/255, blue: 125/255, alpha: 1))
case .j1:
return Color(UIColor(red: 1/255, green: 255/255, blue: 0/255, alpha: 1))
case .k1:
return Color(UIColor(red: 125/255, green: 255/255, blue: 1/255, alpha: 1))
case .l1:
return Color(UIColor(red: 190/255, green: 255/255, blue: 4/255, alpha: 1))
case .m1:
return Color(UIColor(red: 255/255, green: 255/255, blue: 0/255, alpha: 1))
case .n1:
return Color(UIColor(red: 255/255, green: 190/255, blue: 0/255, alpha: 1))
case .o1:
return Color(UIColor(red: 255/255, green: 125/255, blue: 0/255, alpha: 1))
case .p1:
return Color(UIColor(red: 255/255, green: 2/255, blue: 0/255, alpha: 1))
case .q1:
return Color(UIColor(red: 255/255, green: 0/255, blue: 125/255, alpha: 1))
case .r1:
return Color(UIColor(red: 255/255, green: 0/255, blue: 190/255, alpha: 1))
}
}
}
struct ContentView: View {
let buttons: [[ChromaButton]] = [
[.a1, .a1, .a1, .a1, .a1, .a1, .a1, .a1],
[.b1, .b1, .b1, .b1, .b1, .b1, .b1, .b1],
[.c1, .c1, .c1, .c1, .c1, .c1, .c1, .c1],
[.d1, .d1, .d1, .d1, .d1, .d1, .d1, .d1],
[.e1, .e1, .e1, .e1, .e1, .e1, .e1, .e1],
[.f1, .f1, .f1, .f1, .f1, .f1, .f1, .f1],
[.g1, .g1, .g1, .g1, .g1, .g1, .g1, .g1],
[.h1, .h1, .h1, .h1, .h1, .h1, .h1, .h1],
[.i1, .i1, .i1, .i1, .i1, .i1, .i1, .i1],
[.j1, .j1, .j1, .j1, .j1, .j1, .j1, .j1],
[.k1, .k1, .k1, .k1, .k1, .k1, .k1, .k1],
[.l1, .l1, .l1, .l1, .l1, .l1, .l1, .l1],
[.m1, .m1, .m1, .m1, .m1, .m1, .m1, .m1],
[.n1, .n1, .n1, .n1, .n1, .n1, .n1, .n1],
[.o1, .o1, .o1, .o1, .o1, .o1, .o1, .o1],
[.p1, .p1, .p1, .p1, .p1, .p1, .p1, .p1],
[.q1, .q1, .q1, .q1, .q1, .q1, .q1, .q1],
[.r1, .r1, .r1, .r1, .r1, .r1, .r1, .r1]
]
func rdmColor() β String {
return β.a1β
}
var body: some View {
ZStack{
Color.white.edgesIgnoringSafeArea(.all)
VStack{
Spacer()
ForEach(buttons, id: \.self) { row in
HStack(spacing: 35){
ForEach(row, id: \.self) { item in
Button(action:{
}, label: {
Text(item.rawValue)
.font(.system(size:32))
.frame(
width: self.buttonWidth(item: item),
height: self.buttonHeight())
.background(item.buttonColor)
.foregroundColor(.white)
.cornerRadius(self.buttonWidth(item: item)/2)
})
}
}
}
.padding(.bottom, 5)
}
}
}
//
func buttonWidth(item: ChromaButton) -> CGFloat {
return (UIScreen.main.bounds.width - (9*12)) / 14
}
//
func buttonHeight() -> CGFloat {
return (UIScreen.main.bounds.width - (9*12)) / 14
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}