Skip to content

Instantly share code, notes, and snippets.

struct StarsRating: View {
@State var rating : [Rating] = []
func addStars (index : Int) {
var currentRating : Rating = .oneStar
rating.removeAll()
for _ in 0 ... index {
rating.append(currentRating)
currentRating = currentRating.next()
}
}
enum Rating : Int, CaseIterable {
case oneStar = 1
case twoStars = 2
case threeStars = 3
case fourStars = 4
case fiveStars = 5
}
enum OrderState : String, CaseIterable {
case shoppingCart = "cart"
case payment = "creditcard.fill"
case shippingLocation = "mappin.and.ellipse"
case complete = "shippingbox.fill"
}
import SwiftUI
struct PurchasingSteps: View {
@State var orderStatus : [OrderState] = [.shoppingCart]
@State var currentStatus : OrderState = .shoppingCart
var body: some View {
ZStack {
VStack {
// MULTI-STEPS View
struct FoodDeliveryDetailed: View {
let icon : String
let color : Color
let text : String
var body: some View {
VStack {
Spacer()
ZStack {
Circle().fill(.ultraThinMaterial.opacity(0.3))
enum FoodDeliveryState : String, CaseIterable {
case orderReceived = "checkmark.circle"
case preparingOrder = "takeoutbag.and.cup.and.straw"
case onItsWay = "bicycle"
case delivered = "house"
}
import SwiftUI
struct FoodDelivery: View {
@State var foodDeliveryStatus : [FoodDeliveryState] = [.orderReceived]
@State var currentStatus : FoodDeliveryState = .orderReceived
@State var currentColor : Color = .teal
@State var accentColor : Color = .teal
struct MultiStepsView <T, Content: View> : View where T: Swift.CaseIterable {
@Binding var steps: [T]
let extraContent : [String]?
let extraContentPosition : ExtraContentPosition?
let extraContentSize : CGSize?
let action : (Int) -> Void
@ViewBuilder let content: () -> Content
@State var numberOfSteps : Int = 0
@State var widthOfLastItem = 0.0
enum ExtraContentPosition {
case above
case inline
case onTop
}
struct ExtraStepContent: View {
let index : Int
let color : Color
let extraContent : [String]
let extraContentSize : CGSize?
var body: some View {
ZStack {
if let extra = extraContent[index] {
if UIImage(systemName: extra) != nil {
Image(systemName: extra)