Created
August 10, 2023 15:49
-
-
Save 10Macit/4515a3939b166289321c01785b7af523 to your computer and use it in GitHub Desktop.
Single star view for SwiftUI
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// 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