This app use the math_operation library.
Apply AutoLayout via Geometry Reader
![]() | ![]() |
varbuttonsView:someView{letbuttons:[[(String,()->Void)]]=[[("7",{self.buttonClickEvent("7")}),("8",{self.buttonClickEvent("8")}),("9",{self.buttonClickEvent("9")}),("C",{self.buttonClickEvent("C")}),("AC",{self.buttonClickEvent("AC")})],[("4",{self.buttonClickEvent("4")}),("5",{self.buttonClickEvent("5")}),("6",{self.buttonClickEvent("6")}),("+",{self.buttonClickEvent("+")}),("-",{self.buttonClickEvent("-")})],[("1",{self.buttonClickEvent("1")}),("2",{self.buttonClickEvent("2")}),("3",{self.buttonClickEvent("3")}),("*",{self.buttonClickEvent("*")}),("/",{self.buttonClickEvent("/")})],[("0",{self.buttonClickEvent("0")}),(".",{self.buttonClickEvent(".")}),("00",{self.buttonClickEvent("00")}),("=",{self.buttonCalculate()}),("",{self.buttonCalculate()})]]returnGeometryReader{ geometry inVStack(spacing:0){ForEach(0..<buttons.count, id: \.self){ rowIndex inHStack(spacing:0){ForEach(0..<buttons[rowIndex].count, id: \.self){ columnIndex inletbutton=buttons[rowIndex][columnIndex]Button(action: button.1){Text(button.0).font(.largeTitle).foregroundColor(.white).frame(width:self.calculateButtonWidth(containerWidth: geometry.size.width, buttonCount:buttons[rowIndex].count), height:calculateButtonHeight(containerHeight: geometry.size.height, buttonCount: buttons.count)).background(self.buttonColor(button.0))}}}}}.frame(width: geometry.size.width)}}
