Autumn Sale50% offCOMPOT
Cards & Content DisplaysFree ComponentiOS 16.0+Xcode 15+

Rating View (Half-Star Capable)

Dynamic 5-star rating view supporting full, half, and empty star states.

SwiftUI Implementation

Pure Vanilla Swift • No Dependencies
ratingView.swift
import Foundation
import SwiftUI

struct RatingView: View {
    let rating: Double

    var body: some View {
        HStack(alignment: .lastTextBaseline, spacing: 3) {
            ForEach(0..<5) { index in
                if rating >= Double(index + 1) {
                    Image(systemName: "star.fill")
                        .foregroundStyle(.yellow)
                } else if rating > Double(index) && rating < Double(index + 1) {
                    Image(systemName: "star.leadinghalf.filled")
                        .foregroundStyle(.yellow)
                } else {
                    Image(systemName: "star")
                        .foregroundStyle(.gray)
                }
            }
            Text(String(format: "%.1f", rating))
                .padding(.leading, 5)
                .foregroundStyle(.secondary)
        }
    }
}

struct UseRatingView: View {
    var body: some View {
        RatingView(rating: 4.5)
    }
}

#Preview {
    UseRatingView()
}

Ready to copy and paste directly into any Xcode project running iOS 16.0+.

Recommended Use Cases

  • First-run onboarding flows and feature introductions
  • Paywalls, upgrade prompts, and subscription tiers
  • Dashboard overviews, stats tracking, and metric highlights

Component Details

iOS Compatibility
iOS 16.0+
Xcode Version
Xcode 15+
Platform
iOS
License Tier
Free
Themes & Contexts
dashboardonboardingpaywall
Keywords
ratingstarsreviewfeedback
C

Compot for iOS

Native SwiftUI playground app

Preview all 130+ components interactively on your device and copy code straight to Xcode with 1 tap.

Get Compot on the App Store