Mobile App Development 2021W Lecture 16

From Soma-notes
Revision as of 13:26, 15 March 2021 by Soma (talk | contribs) (Created page with "==iOS TapDemo== ===ContentView.swift=== <syntaxhighlight lang="swift" line> // // ContentView.swift // Shared // // Created by Anil Somayaji on 2021-03-15. // import Swi...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

iOS TapDemo

ContentView.swift

//
//  ContentView.swift
//  Shared
//
//  Created by Anil Somayaji on 2021-03-15.
//

import SwiftUI

struct ContentView: View {
    @State var count = 0
    var body: some View {
        VStack{
            Button("Tap here!", action: onTapped)
                .font(/*@START_MENU_TOKEN@*/.title/*@END_MENU_TOKEN@*/)
            
            Text("You have tapped \(count) times.")
            .padding()
        }
    }
    func onTapped() {
        count = count + 1
    }
}

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