⭐️ Fully customizable star ratings for iOS.
- Custom maximum rating value (default: 5)
- Support for decimal rating values (e.g., 3.5 stars)
- Custom images
- Custom size
- Rate using both tap and pan gestures
Create a simple rating control with default settings:
let ratingControl = RatingControl()
ratingControl.value = 3.5 // Set initial rating
Customize appearance and behavior:
let ratingControl = RatingControl()
ratingControl.maxValue = 7 // 7 stars instead of default 5
ratingControl.value = 4.5
ratingControl.spacing = 8 // Increase spacing between stars
ratingControl.tintColor = .systemOrange // Change color
ratingControl.emptyImage = UIImage(systemName: "heart")! // Custom empty image
ratingControl.image = UIImage(systemName: "heart.fill")! // Custom filled image
Listen for rating changes:
ratingControl.addTarget(self, action: #selector(ratingChanged), for: .valueChanged)
@objc func ratingChanged(_ sender: RatingControl) {
print("New rating: \(sender.value)")
}
Alternatively, disable user interaction:
ratingControl.isUserInteractionEnabled = false
Use the SwiftUI wrapper to integrate ratings in your SwiftUI views:
struct ContentView: View {
@State private var rating: Double = 3.5
var body: some View {
VStack {
// Basic usage
RatingView(value: $rating)
// Show current value
Text("Rating: \(rating, specifier: "%.1f")")
// Customization
RatingView(value: $rating, maxValue: 7)
.emptyImage(UIImage(systemName: "heart")!)
.filledImage(UIImage(systemName: "heart.fill")!)
.spacing(10)
.imageSize(CGSize(width: 32, height: 32))
.accentColor(.red)
// Fixed (non-interactive) rating
RatingView(value: 4.5)
.disabled(true)
}
}
}
emptyImage(_:)
- Sets the image for empty (unfilled) partsfilledImage(_:)
- Sets the image for filled partsspacing(_:)
- Sets spacing between imagesimageSize(_:)
- Sets custom size for the images- Use SwiftUI's
.accentColor(_:)
to change the color - Use SwiftUI's
.disabled(_:)
to make it non-interactive
pod 'YSRatingControl'
dependencies: [
.package(url: "https://github.com/yonat/RatingControl", from: "1.0.0")]