Skip to content

Instantly share code, notes, and snippets.

@10Macit
Created August 10, 2023 15:49
Show Gist options
  • Save 10Macit/4515a3939b166289321c01785b7af523 to your computer and use it in GitHub Desktop.
Save 10Macit/4515a3939b166289321c01785b7af523 to your computer and use it in GitHub Desktop.
Single star view for SwiftUI
//
// RatingView.swift
// Bulba
//
// Created by Samet Macit on 9.08.2023.
//
import SwiftUI
struct SingleStarView: View {
/// 0.0 - 1.0
var fillValue: Double
var color: Color
var body: some View {
GeometryReader { geometry in
ZStack(alignment: .leading) {
Image(systemName: "star.fill")
.resizable()
.frame(width: geometry.size.width, height: geometry.size.width)
.foregroundColor(color.opacity(0.2))
Rectangle()
.fill(color)
.frame(width: geometry.size.width * fillValue)
}
.mask(
Image(systemName: "star.fill")
.resizable()
.frame(width: geometry.size.width, height: geometry.size.width)
)
}
.aspectRatio(1, contentMode: .fit)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment