Skip to content

Using Cosmos with SwiftUI

Evgenii Neumerzhitckii edited this page Jul 3, 2020 · 5 revisions
import SwiftUI

struct MyCosmosView: UIViewRepresentable {
    @Binding var rating: Double

    func makeUIView(context: Context) -> CosmosView {
        CosmosView()
    }

    func updateUIView(_ uiView: CosmosView, context: Context) {
        uiView.rating = rating
    
        uiView.setContentHuggingPriority(.defaultHigh, for: .vertical)
    
        uiView.setContentHuggingPriority(.defaultHigh, for: .horizontal)
      
        uiView.settings.starSize = 40
    }
}

struct ContentView: View {
  @State var rating = 3.0
  
    var body: some View {
        MyCosmosView(rating: $rating)
    }
}

struct ContentView_Previews: PreviewProvider {
    static var previews: some View {
        ContentView()
    }
}
Clone this wiki locally