Skip to content
Star Rating preview
Rendered from the SwiftUI source on this page.

Star Rating

From syxUI — written for both platforms, not translated between them.

A self-contained star rating — SwiftUI, styled from system tokens.

Inputs · SwiftUI · iOS 17

  • inputs
  • swiftui

The actual source

StarRatingCard.swift
// Star Rating · syxUI · https://syxui.dev/components/form-rating
// Free in any project. Keep this line and credit syxUI where a person can read it.

import SwiftUI

extension View {
    func formaCard(_ pad: CGFloat = 18) -> some View {
        self.padding(pad)
            .background(Color(.systemBackground), in: RoundedRectangle(cornerRadius: 20, style: .continuous))
            .overlay(RoundedRectangle(cornerRadius: 20, style: .continuous).stroke(Color.primary.opacity(0.06), lineWidth: 1))
            .shadow(color: .black.opacity(0.05), radius: 14, x: 0, y: 6)
    }
}

// Star rating
struct StarRatingCard: View {
    var body: some View {
        VStack(spacing: 12) {
            Text("Rate this tool").font(.system(size: 15, weight: .semibold))
            HStack(spacing: 8) {
                ForEach(0..<5, id: \.self) { i in
                    Image(systemName: i < 4 ? "star.fill" : "star").font(.system(size: 28)).foregroundStyle(i < 4 ? Color.primary : Color.primary.opacity(0.2))
                }
            }
            Text("4.0 · Tap to rate").font(.system(size: 13)).foregroundStyle(.secondary)
        }.frame(maxWidth: .infinity).formaCard()
    }
}
iOS 17 · 1 dependencies

Dependencies

SwiftUI
  • formaCard

Requires iOS 17