Skip to content

Instantly share code, notes, and snippets.

struct InnerCircle: Shape {
let ratio: CGFloat
func path(in rect: CGRect) -> Path {
let center = CGPoint.init(x: (rect.origin.x + rect.width)/2, y: (rect.origin.y + rect.height)/2)
let radii = min(center.x, center.y) * ratio
let path = Path { p in
p.addArc(center: center,
radius: radii,
startAngle: Angle(degrees: 0),
endAngle: Angle(degrees: 360),
struct PieChart: View {
@State private var selectedCell: UUID = UUID()
let dataModel: ChartDataModel
let onTap: (ChartCellModel?) -> ()
var body: some View {
ZStack {
ForEach(dataModel.chartCellModel) { dataSet in
PieChartCell(startAngle: self.dataModel.angle(for: dataSet.value), endAngle: self.dataModel.startingAngle)
.foregroundColor(dataSet.color)
//
// PieChart.swift
// NokiaGame
//
// Created by Prafulla Singh on 13/9/20.
// Copyright © 2020 Prafulla Singh. All rights reserved.
//
import SwiftUI
struct ChartCellModel: Identifiable {
let id = UUID()
let color: Color
let value: CGFloat
let name: String
}
final class ChartDataModel: ObservableObject {
var chartCellModel: [ChartCellModel]
var startingAngle = Angle(degrees: 0)
struct PieChartCell: Shape {
let startAngle: Angle
let endAngle: Angle
func path(in rect: CGRect) -> Path {
let center = CGPoint.init(x: (rect.origin.x + rect.width)/2, y: (rect.origin.y + rect.height)/2)
let radii = min(center.x, center.y)
let path = Path { p in
p.addArc(center: center,
radius: radii,
startAngle: startAngle,
import SwiftUI
enum StylesSet {
struct CustomButton: PrimitiveButtonStyle {
func makeBody(configuration: Configuration) -> some View {
Button(configuration)
.padding()
.frame(minWidth: 0, maxWidth: .infinity)
.background(LinearGradient(gradient: Gradient(colors: [Color.red, Color.green]), startPoint: .leading, endPoint: .trailing))
.cornerRadius(40)
import SwiftUI
enum StylesSet {
struct CustomToggle: ToggleStyle {
func makeBody(configuration: Configuration) -> some View {
HStack {
configuration.label
Spacer()
Rectangle()
.foregroundColor(configuration.isOn ? .red : .green)
struct CustomLabelOnNavigationIOS14: View {
var body: some View {
NavigationView {
Text("CustomLabelOnNavigationIOS14")
.navigationBarTitleDisplayMode(.inline)
.toolbar(items: {
ToolbarItem(placement: .principal) {
VStack {
Image(systemName: "person.circle.fill")
Spacer()
struct CustomBackOnNavigation: View {
var body: some View {
NavigationView {
NavigationLink(destination : DestinationView()) {
Text("Custom Back Nav")
}
.navigationBarTitle("Custom Back Nav")
}
}
}
struct DemoNavColor: View {
init() {
UINavigationBar.appearance().tintColor = .gray
UINavigationBar.appearance().shadowImage = UIImage()
UINavigationBar.appearance().isTranslucent = false
}
var body: some View {
NavigationView {
Text("DemoNavColor")