RSRatingView is a simple Star Rating View for displaying and editing star ratings. Works with Interface Builder
Use SPM to install this library
- Add a UIView to your interface
- In the Identiy Inspector, change Class to
RSRatingView
- In the Attributes Inspector you can now set:
- the rating (Float between 0 and 5)
- the star color
- the Star Rounding Raw Value - IBInspectable can't handle enums, hence the raw value, see ENUM code below
- By checking User Interaction Enabled users can touch the view to enter a star rating. The rating stars updates while touching.
- Create an instance of
RSRatingView
let starRatingView = RSRatingView(frame: CGRect(origin: .zero, size: CGSize(width: 250, height: 50)), rating: 3.5, color: .systemOrange, starRounding: .roundToHalfStar)
Natural aspect ratio is 5 width to 1 height. 2. Add the view as a subview 3. Properties (set and get)
starRatingView.rating
(type:Float
)starRatingView.starColor
(type:UIColor
)starRatingView.starRounding
(type:StarRounding
)starRatingView.isUserInteractionEnabled
(type:Bool
)
public enum StarRounding: Int {
case roundToHalfStar = 0
case ceilToHalfStar = 1
case floorToHalfStar = 2
case roundToFullStar = 3
case ceilToFullStar = 4
case floorToFullStar = 5
}
Based on guidove's StarRatingView
RSStarRating is available under the MPL-2.0 license. See the LICENSE file for more info.