https://github.com/yonat/ratingcontrol
⭐️⭐️⭐️⭐️⭐️ Fully customizable star ratings for iOS
https://github.com/yonat/ratingcontrol
Last synced: 3 months ago
JSON representation
⭐️⭐️⭐️⭐️⭐️ Fully customizable star ratings for iOS
- Host: GitHub
- URL: https://github.com/yonat/ratingcontrol
- Owner: yonat
- License: mit
- Created: 2025-04-05T13:02:38.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-04-20T17:58:12.000Z (about 1 year ago)
- Last Synced: 2026-02-17T09:55:34.690Z (4 months ago)
- Language: Swift
- Homepage:
- Size: 68.4 KB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Funding: .github/FUNDING.yml
- License: LICENSE.txt
Awesome Lists containing this project
README
# RatingControl
[](https://swift.org)
[](LICENSE.txt)
[](https://img.shields.io/cocoapods/v/YSRatingControl.svg)
[](http://cocoapods.org/pods/YSRatingControl)
[](http://makeapullrequest.com)
⭐️ Fully customizable star ratings for iOS.

## Features
* 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
## Usage
### Basic Usage
Create a simple rating control with default settings:
```swift
let ratingControl = RatingControl()
ratingControl.value = 3.5 // Set initial rating
```
### Customization
Customize appearance and behavior:
```swift
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
```
### User Interaction
Listen for rating changes:
```swift
ratingControl.addTarget(self, action: #selector(ratingChanged), for: .valueChanged)
@objc func ratingChanged(_ sender: RatingControl) {
print("New rating: \(sender.value)")
}
```
Alternatively, disable user interaction:
```swift
ratingControl.isUserInteractionEnabled = false
```
## SwiftUI Support
### RatingView
Use the SwiftUI wrapper to integrate ratings in your SwiftUI views:
```swift
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)
}
}
}
```
### Available Modifiers
- `emptyImage(_:)` - Sets the image for empty (unfilled) parts
- `filledImage(_:)` - Sets the image for filled parts
- `spacing(_:)` - Sets spacing between images
- `imageSize(_:)` - Sets custom size for the images
- Use SwiftUI's `.accentColor(_:)` to change the color
- Use SwiftUI's `.disabled(_:)` to make it non-interactive
## Installation
### CocoaPods:
```ruby
pod 'YSRatingControl'
```
### Swift Package Manager:
```swift
dependencies: [
.package(url: "https://github.com/yonat/RatingControl", from: "1.0.0")]
```