Skip to content

Instantly share code, notes, and snippets.

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)
//
// 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 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(
import SwiftUI
struct ContentView: View {
var body: some View {
NavigationView {
NavigationLink(destination: DetailView()) {
Text("Simple Text Button") // set .primaryButton() to update
}
.navigationBarTitle("Welcome")
}
}
//
// ContentView.swift
// GaugeViewDemo
//
// Created by Prafulla Singh on 7/6/20.
// Copyright © 2020 Prafulla Singh. All rights reserved.
//
import SwiftUI
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)
}
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
}
}
import SwiftUI
extension CGRect {
/// center of rect
var center: CGPoint {
return CGPoint(x: self.midX, y: self.midY)
}
/// if rect is not square take centered square to draw
var centeredSquare: CGRect {
let width = ceil(min(size.width, size.height))
import SwiftUI
struct Heart: Shape {
func path(in rect: CGRect) -> Path {
let (x, y, width, height) = rect.centeredSquare.flatten()
let lowerPoint = CGPoint(x: x + width / 2, y: (y + height ))
let path = Path { p in
p.move(to: lowerPoint)