evgenyneu / Cosmos

A star rating control for iOS/tvOS written in Swift
MIT License
2.18k stars 366 forks source link

How to change .totalStars property #166

Closed lsamaria closed 4 years ago

lsamaria commented 4 years ago

Please consider submitting the following information (if relevant):

How do I change the totalStars property? When I try I get an error that says:

Screen Shot 2020-07-01 at 1 35 16 PM

When I look inside the pod inside the CosmosDefaultSettings file it's a constant:

/// The total number of stars to be shown.
static let totalStars = 5

I tried changing it to 10 there but it still only showed 5 stars after I ran the project.

Programmatic code, I don't use storyboard:

lazy var starRating: CosmosView = {
    let cosmosView = CosmosView()
    cosmosView.translatesAutoresizingMaskIntoConstraints = false

    cosmosView.rating = 0.0
    cosmosView.settings.starSize = 22.5
    cosmosView.settings.fillMode = .precise
    cosmosView.settings.minTouchRating = 0.0

    cosmosView.totalStars = 10 // *** DOESN'T WORK ***

    return cosmosView
}()
lsamaria commented 4 years ago

I found it, I had to use access it through the settings property first:

cosmosView.settings.totalStars = 10