Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //
- // ContentView.swift
- // MS_lab01
- //
- // Created by student on 06/03/2022.
- // Copyright © 2022 PL. All rights reserved.
- //
- import SwiftUI
- //Zad 1.1
- /*
- struct ContentView: View {
- let DAYS = ["Poniedzialek", "Wtorek", "Droda",
- "Czwartek", "Piatek", "Sobota",
- "Niedziela"]
- @State var dzien: String = ""
- @State var dzienwybor: String = ""
- var body: some View {
- VStack (alignment: .center) {
- Text("Podaj wybrany dzien tygodnia:").foregroundColor(.green)
- .rotation3DEffect(.degrees(45), axis: (x: 1, y: 0, z: 0))
- TextField("Wpisz dzien tygodnia", text: $dzien).multilineTextAlignment(.center)
- Button(action: {
- if (self.DAYS.contains(self.dzien)) {
- self.dzienwybor = self.dzien
- } else {
- self.dzienwybor = ""
- }
- }, label: {
- Text("Zatwierdz wybor")
- })
- .background(Color.red)
- Text("Wybrano: \(dzienwybor)")
- .padding()
- }.padding()
- }
- }
- */
- //Zad.2.1
- /*
- struct ContentView: View {
- var i = 0
- let colors : [Color] = [.red, .orange, .yellow, .green, .blue, .purple]
- var body: some View {
- ZStack (alignment: .leading) {
- ForEach(i ..< colors.count){ color in
- Rectangle()
- .fill(self.colors[color])
- .frame(width:200, height:200)
- .offset(x: CGFloat(color) * 10.0, y: CGFloat(color) * 10.0)
- }
- }
- }
- }
- */
- //Zad.3.1
- /*
- struct ContentView: View {
- @State var i : Int = 0
- var body: some View {
- VStack (alignment: .leading) {
- Text("Wcisnij przycisk")
- Button(action: {self.i += 1}, label: {Text("Wcisnij mnie")})
- Text("Wcisnieto: \(i) razy")
- }
- }
- }
- */
- //Praca domowa
- //Zad.1.2
- /*
- struct ContentView: View{
- @State var x : String = ""
- @State var y : String = ""
- @State var result: Int = 0
- @State var res : String = ""
- @State var error : String = "ERROR"
- var body: some View{
- VStack(alignment: .leading){
- Text("Wpisz pierwsza liczbe")
- TextField("Wpisz liczbe", text: $x)
- Text("Wpisz druga liczbe")
- TextField("Wpisz liczbe", text: $y)
- Button(action:{
- if let a = Int(x), let b = Int(y){
- result = a * b
- res = "Wynik to: \(result)"
- } else {
- res = "Wynik to: \(error)"
- }
- }, label:{
- Text("Policz")
- })
- Text(res)
- }
- }
- }
- */
- //Zad.2.3.
- /*
- struct ContentView: View{
- @State var a : Int = 0
- @State var b : Int = 0
- @State var c : Int = 0
- @State var res : String = ""
- var body: some View{
- VStack(alignment: .leading){
- HStack{
- Text("Podaj bok 1:")
- TextField("promien", text: Binding(
- get:{String(a)},
- set:{a = Int($0) ?? 0}
- )).textFieldStyle(.roundedBorder).border(Color.green, width: 2)}
- HStack{
- Text("Podaj bok 2:")
- TextField("promien", text: Binding(
- get:{String(b)},
- set:{b = Int($0) ?? 0}
- )).textFieldStyle(.roundedBorder).border(Color.blue, width: 2)}
- HStack{
- Text("Podaj bok 3:")
- TextField("promien", text: Binding(
- get:{String(c)},
- set:{c = Int($0) ?? 0}
- )).textFieldStyle(.roundedBorder).border(Color.yellow, width: 2)}
- Text("Podano \(a), \(b), \(c)")
- Button(action: {
- if(a > 0 && b > 0 && c > 0){
- if (a + b > c && b + c > a && a + c > b){
- res = "Mozna zbudowac trojkat"
- } else {
- res = "Nie mozna zbubowac trojkata"
- }
- } else {
- res = "Podano zle dane"
- }
- }, label: {(Text("Sprawdz").foregroundColor(Color.black))}
- ).background(Color.gray).cornerRadius(25)
- Text(res).foregroundColor(Color.red)}
- }
- }
- */
- //Zad.2.4
- /*
- struct ContentView: View{
- @State var x : Int = 0
- @State var y : Int = 0
- @State var d : String = ""
- @State var er : String = ""
- @State var res : String = ""
- @State var f_res : Float = 0.0
- @State var ok : Bool = true
- let dz = ["+", "-", "*", "/"]
- var body: some View{
- VStack(alignment: .leading){
- HStack{
- Text("Podaj liczbe")
- TextField("Liczba", text: Binding(
- get:{String(x)},
- set:{x = Int($0) ?? 0}))
- }
- HStack{
- Text("Podaj liczbe")
- TextField("Liczba", text: Binding(
- get:{String(y)},
- set:{y = Int($0) ?? 0}))
- }
- HStack{
- Text("Podaj dzialanie")
- TextField("+ - * /", text: $d)
- }
- Button(action:{
- switch d{
- case "+":
- res = "Wynik \(x+y)"
- break
- case "-":
- res = "Wynik \(x-y)"
- break
- case "*":
- res = "Wynik \(x*y)"
- break
- case "/":
- if(y == 0){
- er = "Nie mozna dzielic przez 0"
- ok = false
- break
- } else {
- if (x % y == 0){
- res = "Wynik \(x/y)"
- } else {
- res = "Wynik \(Float(x) / Float(y))"
- }
- break
- }
- default:
- er = "Podano nieznana operacje"
- ok = false
- break
- }
- },
- label: {(Text("Policz"))}
- )
- if(ok == true){
- Text(res)
- } else {
- Text(er)
- }
- }
- }
- }
- */
- //Zad.3.2.
- /*
- struct ContentView: View{
- enum Opony: String, CaseIterable, Identifiable{
- case one = "17 cali"
- case two = "18 cali"
- var id: String{self.rawValue}
- }
- enum Op_com: String, CaseIterable, Identifiable{
- case one = "Pirelli"
- case two = "Debica"
- var id: String{self.rawValue}
- }
- @State var sel_op: Opony = .one
- @State var sel_op_com: Op_com = .one
- @State var x : Int = 0
- @State var res : String = ""
- @State var pir_17c : Int = 10
- @State var deb_17c : Int = 5
- @State var pir_18c : Int = 6
- @State var deb_18c : Int = 15
- var body: some View{
- VStack{
- Picker(selection: $sel_op,
- label: Text("Opony"),
- content: {
- ForEach(Opony.allCases) { option in
- Text(option.rawValue.capitalized).tag(option)
- }
- }).padding().pickerStyle(SegmentedPickerStyle())
- //Text("Selected value \(sel_op.rawValue)")
- Picker(selection: $sel_op_com,
- label: Text("Firmy"),
- content: {
- ForEach(Op_com.allCases) {option in
- Text(option.rawValue).tag(option)
- }
- }).padding().pickerStyle(SegmentedPickerStyle())
- HStack{
- Text("Wpisz liczbe opon")
- TextField("Liczba", text: Binding(
- get:{String(x)},
- set:{x = Int($0) ?? 0})).keyboardType(.numberPad)
- }
- Button(
- action: {
- if(x < 0 || x == 0){
- res = "Wprowadzono nieprawidlowa liczbe opon"
- } else{
- if(sel_op.rawValue == "17 cali" && sel_op_com.rawValue == "Pirelli"){
- if (x <= pir_17c){
- res = "Mozesz kupic"
- } else {
- res = "Nie mozesz kupic"
- }
- }
- if(sel_op.rawValue == "18 cali" && sel_op_com.rawValue == "Pirelli"){
- if (x <= pir_18c){
- res = "Mozesz kupic"
- } else {
- res = "Nie mozesz kupic"
- }
- }
- if(sel_op.rawValue == "17 cali" && sel_op_com.rawValue == "Debica"){
- if (x <= deb_17c){
- res = "Mozesz kupic"
- } else {
- res = "Nie mozesz kupic"
- }
- }
- if(sel_op.rawValue == "18 cali" && sel_op_com.rawValue == "Debica"){
- if (x <= deb_18c){
- res = "Mozesz kupic"
- } else {
- res = "Nie mozesz kupic"
- }
- }
- }},
- label: {Text("Sprawdz")}
- )
- Text(res)
- }
- }
- }
- */
- struct ContentView: View{
- var body: some View{
- VStack{
- Text("Hello World")
- }
- }
- }
- struct ContentView_Previews: PreviewProvider {
- static var previews: some View {
- ContentView()
- }
- }
Add Comment
Please, Sign In to add comment