Codigo Calculadora
Codigo Calculadora
// ContentView.swift
// Practica14_2025
//
// Created by Victor
Manuel Calderon Hernandez
on 28/03/25.
//
import SwiftUI
.background(.gray.opacity(
0.3))
.font(.system(size: 40))
.foregroundColor(.black)
.cornerRadius(20)
.multilineTextAlignment(.t
railing)
HStack{
Button(action: {
Circle()
.frame(width: tamCirculo,
height: tamCirculo)
.overlay(content: {
Text("7")
.foregroundColor(.white)
.font(.system(size:
tamTexto))
})
})
Button(action: {
Circle()
.frame(width: tamCirculo,
height: tamCirculo)
.overlay(content: {
Text("8")
.foregroundColor(.white)
.font(.system(size:
tamTexto))
})
})
Button(action: {
.frame(width: tamCirculo,
height: tamCirculo)
.overlay(content: {
Text("9")
.foregroundColor(.white)
.font(.system(size:
tamTexto))
})
})
Button(action: {
num1 =
Int(pantalla)!
operacion = "/"
pantalla = ""
}, label:
{
Circle()
.fill(Color.orange)
.frame(width: tamCirculo,
height: tamCirculo)
.overlay(content: {
Text("/")
.foregroundColor(.white)
.font(.system(size:
tamTexto))
})
})
}
HStack{
Button(action: {
.frame(width: tamCirculo,
height: tamCirculo)
.overlay(content: {
Text("4")
.foregroundColor(.white)
.font(.system(size:
tamTexto))
})
})
Button(action: {
pantalla = pantalla + "5"
}, label:
{
Circle()
.frame(width: tamCirculo,
height: tamCirculo)
.overlay(content: {
Text("5")
.foregroundColor(.white)
.font(.system(size:
tamTexto))
})
})
Button(action: {
Circle()
.frame(width: tamCirculo,
height: tamCirculo)
.overlay(content: {
Text("6")
.foregroundColor(.white)
.font(.system(size:
tamTexto))
})
})
Button(action: {
num1 =
Int(pantalla)!
operacion = "*"
pantalla = ""
}, label:
{
Circle()
.fill(Color.orange)
.frame(width: tamCirculo,
height: tamCirculo)
.overlay(content: {
Text("*")
.foregroundColor(.white)
.font(.system(size:
tamTexto))
})
})
}
HStack{
Button(action: {
Circle()
.frame(width: tamCirculo,
height: tamCirculo)
.overlay(content: {
Text("1")
.foregroundColor(.white)
.font(.system(size:
tamTexto))
})
})
Button(action: {
Circle()
.frame(width: tamCirculo,
height: tamCirculo)
.overlay(content: {
Text("2")
.foregroundColor(.white)
.font(.system(size:
tamTexto))
})
})
Button(action: {
Circle()
.frame(width: tamCirculo,
height: tamCirculo)
.overlay(content: {
Text("3")
.foregroundColor(.white)
.font(.system(size:
tamTexto))
})
})
Button(action: {
num1 =
Int(pantalla)!
operacion = "-"
pantalla = ""
}, label:
{
Circle()
.fill(Color.orange)
.frame(width: tamCirculo,
height: tamCirculo)
.overlay(content: {
Text("-")
.foregroundColor(.white)
.font(.system(size:
tamTexto))
})
})
}
HStack{
Button(action: {
num2 =
Int(pantalla)!
switch
operacion{
case
"/":
pantalla = String(num1 /
num2)
break
case
"*":
pantalla = String(num1 *
num2)
break
case
"-":
pantalla = String(num1 -
num2)
break
case
"+":
pantalla = String(num1 +
num2)
break
default:
break
}
}, label:
{
Circle()
.frame(width: tamCirculo,
height: tamCirculo)
.overlay(content: {
Text("=")
.foregroundColor(.white)
.font(.system(size:
tamTexto))
})
})
Button(action: {
Circle()
.frame(width: tamCirculo,
height: tamCirculo)
.overlay(content: {
Text("0")
.foregroundColor(.white)
.font(.system(size:
tamTexto))
})
})
Button(action: {
pantalla = ""
num1 =
0
num2 =
0
operacion = ""
}, label:
{
Circle()
.frame(width: tamCirculo,
height: tamCirculo)
.overlay(content: {
Text("C")
.foregroundColor(.white)
.font(.system(size:
tamTexto))
})
})
Button(action: {
num1 =
Int(pantalla)!
operacion = "+"
pantalla = ""
}, label:
{
Circle()
.fill(Color.orange)
.frame(width: tamCirculo,
height: tamCirculo)
.overlay(content: {
Text("+")
.foregroundColor(.white)
.font(.system(size:
tamTexto))
})
})
}
}
//Spacer()
.padding()
}
}
#Preview {
ContentView()
}