Maszi

Untitled

Mar 12th, 2022 (edited)
564
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 9.96 KB | None | 0 0
  1. //
  2. //  ContentView.swift
  3. //  MS_lab01
  4. //
  5. //  Created by student on 06/03/2022.
  6. //  Copyright © 2022 PL. All rights reserved.
  7. //
  8.  
  9. import SwiftUI
  10.  
  11. //Zad 1.1
  12. /*
  13. struct ContentView: View {
  14.     let DAYS = ["Poniedzialek", "Wtorek", "Droda",
  15.                 "Czwartek", "Piatek", "Sobota",
  16.                 "Niedziela"]
  17.     @State var dzien: String = ""
  18.     @State var dzienwybor: String = ""
  19.     var body: some View {
  20.         VStack (alignment: .center) {
  21.             Text("Podaj wybrany dzien tygodnia:").foregroundColor(.green)
  22.                 .rotation3DEffect(.degrees(45), axis: (x: 1, y: 0, z: 0))
  23.             TextField("Wpisz dzien tygodnia", text: $dzien).multilineTextAlignment(.center)
  24.             Button(action: {
  25.                 if (self.DAYS.contains(self.dzien)) {
  26.                     self.dzienwybor = self.dzien
  27.                 } else {
  28.                     self.dzienwybor = ""
  29.                 }
  30.             }, label: {
  31.                 Text("Zatwierdz wybor")
  32.             })
  33.                 .background(Color.red)
  34.                 Text("Wybrano: \(dzienwybor)")
  35.                     .padding()
  36.         }.padding()
  37.     }
  38. }
  39. */
  40.  
  41. //Zad.2.1
  42. /*
  43. struct ContentView: View {
  44.     var i = 0
  45.     let colors : [Color] = [.red, .orange, .yellow, .green, .blue, .purple]
  46.     var body: some View {
  47.         ZStack (alignment: .leading) {
  48.             ForEach(i ..< colors.count){ color in
  49.                 Rectangle()
  50.                     .fill(self.colors[color])
  51.                     .frame(width:200, height:200)
  52.                     .offset(x: CGFloat(color) * 10.0, y: CGFloat(color) * 10.0)
  53.             }
  54.         }
  55.     }
  56. }
  57. */
  58.  
  59. //Zad.3.1
  60. /*
  61. struct ContentView: View {
  62.     @State var i : Int = 0
  63.     var body: some View {
  64.         VStack (alignment: .leading) {
  65.             Text("Wcisnij przycisk")
  66.             Button(action: {self.i += 1}, label: {Text("Wcisnij mnie")})
  67.             Text("Wcisnieto: \(i) razy")
  68.         }
  69.     }
  70. }
  71. */
  72.  
  73. //Praca domowa
  74. //Zad.1.2
  75. /*
  76. struct ContentView: View{
  77.     @State var x : String = ""
  78.     @State var y : String = ""
  79.     @State var result: Int = 0
  80.     @State var res : String = ""
  81.     @State var error : String = "ERROR"
  82.     var body: some View{
  83.         VStack(alignment: .leading){
  84.             Text("Wpisz pierwsza liczbe")
  85.             TextField("Wpisz liczbe", text: $x)
  86.             Text("Wpisz druga liczbe")
  87.             TextField("Wpisz liczbe", text: $y)
  88.             Button(action:{
  89.                 if let a = Int(x), let b = Int(y){
  90.                     result = a * b
  91.                     res = "Wynik to: \(result)"
  92.                 } else {
  93.                     res = "Wynik to: \(error)"
  94.                 }
  95.             }, label:{
  96.                 Text("Policz")
  97.             })
  98.             Text(res)
  99.         }
  100.     }
  101. }
  102. */
  103.  
  104. //Zad.2.3.
  105. /*
  106. struct ContentView: View{
  107.     @State var a : Int = 0
  108.     @State var b : Int = 0
  109.     @State var c : Int = 0
  110.     @State var res : String = ""
  111.     var body: some View{
  112.         VStack(alignment: .leading){
  113.         HStack{
  114.             Text("Podaj bok 1:")
  115.             TextField("promien", text: Binding(
  116.                 get:{String(a)},
  117.                 set:{a = Int($0) ?? 0}
  118.             )).textFieldStyle(.roundedBorder).border(Color.green, width: 2)}
  119.         HStack{
  120.             Text("Podaj bok 2:")
  121.             TextField("promien", text: Binding(
  122.                 get:{String(b)},
  123.                 set:{b = Int($0) ?? 0}
  124.             )).textFieldStyle(.roundedBorder).border(Color.blue, width: 2)}
  125.         HStack{
  126.             Text("Podaj bok 3:")
  127.             TextField("promien", text: Binding(
  128.                 get:{String(c)},
  129.                 set:{c = Int($0) ?? 0}
  130.             )).textFieldStyle(.roundedBorder).border(Color.yellow, width: 2)}
  131.         Text("Podano \(a), \(b), \(c)")
  132.         Button(action: {
  133.             if(a > 0 && b > 0 && c > 0){
  134.                 if (a + b > c && b + c > a && a + c > b){
  135.                     res = "Mozna zbudowac trojkat"
  136.                 } else {
  137.                     res = "Nie mozna zbubowac trojkata"
  138.                 }
  139.             } else {
  140.                 res = "Podano zle dane"
  141.             }
  142.         }, label: {(Text("Sprawdz").foregroundColor(Color.black))}
  143.         ).background(Color.gray).cornerRadius(25)
  144.         Text(res).foregroundColor(Color.red)}
  145.     }
  146. }
  147. */
  148.  
  149. //Zad.2.4
  150. /*
  151. struct ContentView: View{
  152.     @State var x : Int = 0
  153.     @State var y : Int = 0
  154.     @State var d : String = ""
  155.     @State var er : String = ""
  156.     @State var res : String = ""
  157.     @State var f_res : Float = 0.0
  158.     @State var ok : Bool = true
  159.     let dz = ["+", "-", "*", "/"]
  160.     var body: some View{
  161.         VStack(alignment: .leading){
  162.             HStack{
  163.                 Text("Podaj liczbe")
  164.                 TextField("Liczba", text: Binding(
  165.                     get:{String(x)},
  166.                     set:{x = Int($0) ?? 0}))
  167.             }
  168.             HStack{
  169.                 Text("Podaj liczbe")
  170.                 TextField("Liczba", text: Binding(
  171.                     get:{String(y)},
  172.                     set:{y = Int($0) ?? 0}))
  173.             }
  174.             HStack{
  175.                 Text("Podaj dzialanie")
  176.                 TextField("+ - * /", text: $d)
  177.             }
  178.             Button(action:{
  179.                     switch d{
  180.                         case "+":
  181.                             res = "Wynik \(x+y)"
  182.                             break
  183.                         case "-":
  184.                             res = "Wynik \(x-y)"
  185.                             break
  186.                         case "*":
  187.                             res = "Wynik \(x*y)"
  188.                             break
  189.                         case "/":
  190.                         if(y == 0){
  191.                             er = "Nie mozna dzielic przez 0"
  192.                             ok = false
  193.                             break
  194.                         } else {
  195.                             if (x % y == 0){
  196.                                 res = "Wynik \(x/y)"
  197.                             } else {
  198.                                 res = "Wynik \(Float(x) / Float(y))"
  199.                             }
  200.                             break
  201.                         }
  202.                         default:
  203.                             er = "Podano nieznana operacje"
  204.                             ok = false
  205.                             break
  206.                     }
  207.             },
  208.                    label: {(Text("Policz"))}
  209.             )
  210.             if(ok == true){
  211.                 Text(res)
  212.             } else {
  213.                 Text(er)
  214.             }
  215.         }
  216.     }
  217. }
  218. */
  219.  
  220. //Zad.3.2.
  221. /*
  222. struct ContentView: View{
  223.     enum Opony: String, CaseIterable, Identifiable{
  224.         case one = "17 cali"
  225.         case two = "18 cali"
  226.        
  227.         var id: String{self.rawValue}
  228.     }
  229.     enum Op_com: String, CaseIterable, Identifiable{
  230.         case one = "Pirelli"
  231.         case two = "Debica"
  232.        
  233.         var id: String{self.rawValue}
  234.     }
  235.     @State var sel_op: Opony = .one
  236.     @State var sel_op_com: Op_com = .one
  237.     @State var x : Int = 0
  238.     @State var res : String = ""
  239.     @State var pir_17c : Int = 10
  240.     @State var deb_17c : Int = 5
  241.     @State var pir_18c : Int = 6
  242.     @State var deb_18c : Int = 15
  243.     var body: some View{
  244.         VStack{
  245.             Picker(selection: $sel_op,
  246.                    label: Text("Opony"),
  247.                    content: {
  248.                 ForEach(Opony.allCases) { option in
  249.                     Text(option.rawValue.capitalized).tag(option)
  250.                 }
  251.             }).padding().pickerStyle(SegmentedPickerStyle())
  252.             //Text("Selected value \(sel_op.rawValue)")
  253.             Picker(selection: $sel_op_com,
  254.                    label: Text("Firmy"),
  255.                    content: {
  256.                 ForEach(Op_com.allCases) {option in
  257.                     Text(option.rawValue).tag(option)
  258.                 }
  259.             }).padding().pickerStyle(SegmentedPickerStyle())
  260.             HStack{
  261.                 Text("Wpisz liczbe opon")
  262.                 TextField("Liczba", text: Binding(
  263.                     get:{String(x)},
  264.                     set:{x = Int($0) ?? 0})).keyboardType(.numberPad)
  265.             }
  266.             Button(
  267.                 action: {
  268.                     if(x < 0 || x == 0){
  269.                         res = "Wprowadzono nieprawidlowa liczbe opon"
  270.                     } else{
  271.                     if(sel_op.rawValue == "17 cali" && sel_op_com.rawValue == "Pirelli"){
  272.                         if (x <= pir_17c){
  273.                             res = "Mozesz kupic"
  274.                         } else {
  275.                             res = "Nie mozesz kupic"
  276.                         }
  277.                     }
  278.                     if(sel_op.rawValue == "18 cali" && sel_op_com.rawValue == "Pirelli"){
  279.                         if (x <= pir_18c){
  280.                             res = "Mozesz kupic"
  281.                         } else {
  282.                             res = "Nie mozesz kupic"
  283.                         }
  284.                     }
  285.                     if(sel_op.rawValue == "17 cali" && sel_op_com.rawValue == "Debica"){
  286.                         if (x <= deb_17c){
  287.                             res = "Mozesz kupic"
  288.                         } else {
  289.                             res = "Nie mozesz kupic"
  290.                         }
  291.                     }
  292.                     if(sel_op.rawValue == "18 cali" && sel_op_com.rawValue == "Debica"){
  293.                         if (x <= deb_18c){
  294.                             res = "Mozesz kupic"
  295.                         } else {
  296.                             res = "Nie mozesz kupic"
  297.                         }
  298.                     }
  299.                    
  300.                     }},
  301.                 label: {Text("Sprawdz")}
  302.             )
  303.             Text(res)
  304.         }
  305.     }
  306. }
  307. */
  308. struct ContentView: View{
  309.     var body: some View{
  310.         VStack{
  311.             Text("Hello World")
  312.         }
  313.     }
  314. }
  315. struct ContentView_Previews: PreviewProvider {
  316.     static var previews: some View {
  317.         ContentView()
  318.     }
  319. }
  320.  
Add Comment
Please, Sign In to add comment