Mobile App Dev 2022W: Tutorial 1

From Soma-notes
Revision as of 16:21, 13 January 2022 by Soma (talk | contribs) (Created page with "'''This tutorial is still in development.''' ==Code== <syntaxhighlight lang="swift" line> // square-1, ContentView.swift // // for Tutorial 1, COMP 1601 Winter 2022, Carl...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

This tutorial is still in development.


Code

//  square-1, ContentView.swift
//
//  for Tutorial 1, COMP 1601 Winter 2022, Carleton University
//  Anil Somayaji, 1/13/22.
//

import SwiftUI

struct ContentView: View {
    @State private var sizeS = ""
    var body: some View {
        VStack{
            Text("Square size:")
            TextField("Enter the Size", text: $sizeS)
                .multilineTextAlignment(.center)
            let size = Double(sizeS) ?? 200
            Rectangle()
            // There are many color spaces, see
            // https://developer.apple.com/documentation/coregraphics/cgcolorspace/1408871-srgb
                .stroke(Color(Color.RGBColorSpace.sRGB,
                              red: 0.0, green: 1.0, blue: 0.5),
                        lineWidth: 10)
                .frame(width: size,
                       height: size)
        }
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}