StarView

master

SwiftUI StarView Shape, usable for displaying ratings
EnesKaraosman/StarView

StarView

StarShape, StarView, StarRatingView for SwiftUI

Demo GIF

Installation

Swift Package Manager

Add new package: 'https://github.com/EnesKaraosman/StarView'

Usage

StarRatingView

StarRatingView(starCount: 5, totalPercentage: totalPercentage, style: .init())
    .frame(width: 300, height: 60)

StarRatingView Parameters

  • starCount (optional, default = 5)
  • totalPercentage between: 0 - 100 (ex: 60, fills 3/5 star)
  • style (optional)

StarView

In case you want to use single StarView

StarView(percentage: 50)
    .frame(width: 60, height: 50)

StarView Parameters

  • percentage between: 0 - 100
  • style (optional)

Styling

Pass style parameter in constructor.

let fillColor: Color
let borderWidth: CGFloat
let borderColor: Color
let spacing: CGFloat // For StarRatingView

Full example

@State private var totalPercentage: CGFloat = 20

var body: some View {
    VStack(alignment: .leading) {

        Spacer()
        Text("Individual Star View").font(.title)
        
        StarView(percentage: 50, style: .init())
            .frame(width: 60, height: 50)
        
        Spacer()
        Divider().padding()
        Spacer()
        
        Text("Rating View").font(.title)

        StarRatingView(starCount: 5, totalPercentage: totalPercentage, style: .init())
            .frame(height: 60)
        
        Slider(value: $fillPercentage, in: 0...100) {
            Text("Fill Percantage")
        }.padding(.top, 24)
        
        Spacer()
        
    }
    .padding()
}

Description

  • Swift Tools 5.1.0
View More Packages from this Author

Dependencies

  • None
Last updated: Fri Oct 18 2024 23:12:57 GMT-0900 (Hawaii-Aleutian Daylight Time)