Giter Club home page Giter Club logo

starrating's Introduction

StarRating

Example Example Dark

This is a customizable star rating control written specifically for SwiftUI. It shows a star rating and handles user input. It also contains a star Shape with customizable number of vertices and weight.

Installation

Requirements iOS 13+

Swift Package Manager

  1. In Xcode, open your project and navigate to File → Swift Packages → Add Package Dependency.
  2. Paste the repository URL (https://github.com/dkk/StarRating) and click Next.
  3. For Rules, select version.
  4. Click Finish.

Swift Package

.package(url: "https://github.com/dkk/StarRating", .upToNextMajor(from: "1.2.0"))

Usage

Import StarRating package to your view.

import StarRating

and you are ready to use StarRating or the Shape Star in you SwiftUI code.

Use StarRating to display a rating

You can display a rating with the line:

// set the rating you want to display as initialRating
StarRating(initialRating: 3.7) 

Use StarRating to get a rating from the user

To show a fully functional star rating that can handle user input, add the line:

// set the initialRating
// add a callback to do something with the new rating
StarRating(initialRating: 0, onRatingChanged: { print($0) })

Configure StarRating

To configure the control, StarRating binds a StarRatingConfiguration object. This makes it easy to dynamically change the control's style and behaviour.

  1. Create a StarRatingConfiguration object:
@State var customConfig = StarRatingConfiguration(minRating: 2, numberOfStars: 10)
  1. Pass it when creating the instance of StarRating and update it later as needed:
StarRating(initialRating: 2.0, configuration: $customConfig) { newRating in
    customConfig.starVertices = Int(newRating)
}

Read the implementation of StarRatingConfiguration to see what configuration posibilities are available at the moment.

Use the Star Shape

Use Star the same way as you would use standard SwiftUI Shapes, such as Rectangle. Star allows to configure the number of vertices and the weight. Example usage:

Star(vertices: 5, weight: 0.45)

Contribute

You can contribute to this project by helping me solve any reported issues or feature requests and creating a pull request.

Support

If you just want to say thanks, you could buy me a coffee ☕️.

License

StarRating is released under the MIT License.

starrating's People

Contributors

dkk avatar

Stargazers

Yufeng Wu avatar paul avatar Tom Krikorian avatar Fahim Rahman avatar Prakash avatar Zion avatar  avatar Nekane avatar Kyle Howells avatar  avatar  avatar George Bellos avatar Thanos Bellos avatar XiaoDong avatar  avatar  avatar Kino avatar ShadowParticle avatar Carabineiro avatar John Nguyen avatar Yevhen avatar  avatar Segun Awe avatar  avatar Ramūnas avatar

Watchers

 avatar  avatar James Cloos avatar Carabineiro avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.