Last active
July 28, 2020 21:11
-
-
Save donguri9/fdfa881f440e0bafabdfbe055970de1b to your computer and use it in GitHub Desktop.
Stop Watch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
class StopWatchManeger:ObservableObject{ | |
@Published var secondsElapsed = 0.0 | |
var timer = Timer() | |
func start(){ | |
timer = Timer.scheduledTimer(withTimeInterval: 0.1, repeats: true){ timer in | |
self.secondsElapsed += 0.1 | |
} | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
struct ContentView: View { | |
@ObservedObject var stopWatchManeger = StopWatchManeger() | |
var body: some View { | |
VStack { | |
Text(String(format:"%.1f",stopWatchManeger.secondsElapsed)) | |
.font(.custom("Futura", size: 50)) | |
.padding(.top,200) | |
.padding(.bottom,100) | |
.padding(.trailing,100) | |
.padding(.leading,100) | |
Button(action: {self.stopWatchManeger.start()}){ | |
ExtractedView(label: "Start", buttonColor: .yellow, textColor: .black) | |
} | |
Spacer() | |
} | |
} | |
} | |
struct ContentView_Previews: PreviewProvider { | |
static var previews: some View { | |
ContentView() | |
} | |
} | |
struct ExtractedView: View { | |
var label:String | |
var buttonColor:Color | |
var textColor:Color | |
var body: some View { | |
Text(label) | |
.foregroundColor(textColor) | |
.padding(.vertical,20) | |
.padding(.horizontal,90) | |
.background(buttonColor) | |
.cornerRadius(10) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment