forked from VerticalHeretic/iOS-16-MacOS-13-SwiftUI-Showdown
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added all possible gauges implementations
- Loading branch information
1 parent
e87dcd8
commit 6a8fe14
Showing
4 changed files
with
190 additions
and
26 deletions.
There are no files selected for viewing
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// | ||
// GaugeScreen.swift | ||
// iOS16-SwiftUI-Showdown | ||
// | ||
// Created by Łukasz Stachnik on 27/08/2022. | ||
// | ||
|
||
import SwiftUI | ||
|
||
struct GaugeScreen: View { | ||
var feature: Feature | ||
@State private var progress = 0.0 | ||
let timer = Timer.publish(every: 1, on: .main, in: .common).autoconnect() | ||
|
||
var body: some View { | ||
VStack { | ||
Text(feature.description) | ||
.font(.footnote) | ||
.padding() | ||
.multilineTextAlignment(.center) | ||
|
||
|
||
Gauge(value: progress) { | ||
Text("Task progress") | ||
.font(.title) | ||
} currentValueLabel: { | ||
Text(progress.formatted(.percent)) | ||
.font(.footnote) | ||
} minimumValueLabel: { | ||
Text(0.formatted(.percent)) | ||
.font(.footnote) | ||
} maximumValueLabel: { | ||
Text(100.formatted(.percent)) | ||
.font(.footnote) | ||
} | ||
.padding() | ||
|
||
|
||
Gauge(value: progress) { | ||
Text("Status") | ||
.font(.footnote) | ||
} currentValueLabel: { | ||
Text(progress.formatted(.percent)) | ||
.font(.footnote) | ||
} | ||
.padding() | ||
.gaugeStyle(.accessoryCircularCapacity) | ||
.tint(.orange) | ||
|
||
|
||
Gauge(value: progress) { | ||
Text("Status") | ||
.font(.footnote) | ||
} currentValueLabel: { | ||
Text(progress.formatted(.percent)) | ||
.font(.footnote) | ||
} | ||
.scaleEffect(2.0) // To make the circular ones bigger you need to use scaleEffect and for the linear frame will be sufficient | ||
.padding() | ||
.gaugeStyle(.accessoryCircular) | ||
.tint(.indigo) | ||
|
||
Gauge(value: progress) { | ||
Text("Status") | ||
.font(.footnote) | ||
} currentValueLabel: { | ||
Text(progress.formatted(.percent)) | ||
.font(.footnote) | ||
} | ||
.padding() | ||
.gaugeStyle(.accessoryLinearCapacity) | ||
.tint(.pink) | ||
|
||
Spacer() | ||
|
||
} | ||
.onReceive(timer) { _ in | ||
if progress < 1.0 { | ||
withAnimation { | ||
progress += 0.025 | ||
} | ||
} | ||
} | ||
|
||
|
||
.navigationTitle(feature.title) | ||
.navigationBarTitleDisplayMode(.inline) | ||
} | ||
} | ||
|
||
struct GaugeScreen_Previews: PreviewProvider { | ||
static var previews: some View { | ||
GaugeScreen(feature: Feature(title: "Gauge 🔜", | ||
description: "SwiftUI introduces a new view called Gauge for displaying progress. In the most basic form, a gauge has a default range from 0 to 1.", | ||
type: .gauge)) | ||
} | ||
} |