Skip to content

Instantly share code, notes, and snippets.

struct Needle: Shape {
func path(in rect: CGRect) -> Path {
var path = Path()
path.move(to: CGPoint(x: 0, y: rect.height/2))
path.addLine(to: CGPoint(x: rect.width, y: 0))
path.addLine(to: CGPoint(x: rect.width, y: rect.height))
return path
}
}
struct GaugeView: View {
func colorMix(percent: Int) -> Color {
let p = Double(percent)
let tempG = (100.0-p)/100
let g: Double = tempG < 0 ? 0 : tempG
let tempR = 1+(p-100.0)/100.0
let r: Double = tempR < 0 ? 0 : tempR
return Color.init(red: r, green: g, blue: 0)
}
struct GaugeView: View {
func colorMix(percent: Int) -> Color {
let p = Double(percent)
let tempG = (100.0-p)/100
let g: Double = tempG < 0 ? 0 : tempG
let tempR = 1+(p-100.0)/100.0
let r: Double = tempR < 0 ? 0 : tempR
return Color.init(red: r, green: g, blue: 0)
}
//
// ContentView.swift
// GaugeViewDemo
//
// Created by Prafulla Singh on 7/6/20.
// Copyright © 2020 Prafulla Singh. All rights reserved.
//
import SwiftUI
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
NavigationLink(destination: DetailView()) {
Text("Simple Text Button") // set .primaryButton() to update
}
.navigationBarTitle("Welcome")
}
}
import SwiftUI
public struct PrimaryButton: ViewModifier {
public func body(content: Content) -> some View {
content.foregroundColor(Color.theme)
.padding()
.font(Font.system(size: Matrix.paragraphSize,
weight: .semibold,
design: .default))
.overlay(
//
// Toast.swift
// ThemingSwiftUI
//
// Created by Prafulla Singh on 6/6/20.
// Copyright © 2020 Prafulla Singh. All rights reserved.
//
//Picked: https://stackoverflow.com/questions/56550135/swiftui-global-overlay-that-can-be-triggered-from-any-view
import SwiftUI
import Foundation
import SwiftUI
struct PrimaryHeader: ViewModifier {
func body(content: Content) -> some View {
content
.font(Font.system(size: Matrix.headerPrimarySize,
weight: .bold,
design: .default))
.foregroundColor(Color.textHeaderPrimary)
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
// Use this method to optionally configure and attach the UIWindow `window` to the provided UIWindowScene `scene`.
// If using a storyboard, the `window` property will automatically be initialized and attached to the scene.
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).
import Foundation
import CoreGraphics
class Matrix {
static let headerPrimarySize: CGFloat = 36
static let headerSecondarySize: CGFloat = 27
static let paragraphSize: CGFloat = 18
static let stackViewSpacing: CGFloat = 20
static let cornerRadius: CGFloat = 12