Latest 1.0.9
Homepage https://github.com/crashoverride777/swifty-ratings-view
License MIT
Platforms ios 11.4, requires ARC
Authors

Swifty Ratings View

Swift 4.2
[Platform]()
CocoaPods Compatible

A simpler ratings view. No fuss. Features swipe gesture.

Requirements

  • iOS 11.4+
  • Swift 4.0+

Installation

CocoaPods is a dependency manager for Cocoa projects. Simply install the pod by adding the following line to your pod file

pod 'SwiftyRatingsView'

Altenatively you can drag the swift file(s) and XIBs manually into your project.

Usage

  • Add the import statment when you installed via cocoa pods.
import SwiftyRatingsView 
  • Add to view

Create a lazy property to instantiate the ratingsView. Call the configure method to setup the ratings view and add the callback handler to listen for ratings changes.

private lazy var ratingsView: RatingsView = {
let configuration = RatingsView.Configuration(
    image: UIImage(named: "star")!,
    numberOfItems: 5,
    startRating: 2,
    selectedColor: .orange,
    deselectedColor: .gray
)
$0.configure(with: configuration)
$0.handler = { [weak self] rating in
print(rating)
// Do your thing
}
return $0
}(RatingsView.instantiate())

Now there is 2 ways to add the ratings view to your actual view, stackviews or code.

Way 1, Stack views (preferred)

Add a stack view to your desired view via storyboards/xibs, give it a width and height constraints of. Than create an outlet to your UIView class that will show the ratings view. Finall use didSet to add the ratingsView.

@IBOutlet weak var ratingsStackView: UIStackView! {
    didSet {
        ratingsStackView.addArrangedSubview(ratingsView)
    }
}

Way 2, code

view.addSubview(ratingsView)
ratingsView.translatesAutoresizingMaskIntoConstraints = false
ratingsView.widthAnchor.constraint(equalToConstant: 160).isActive = true
ratingsView.heightAnchor.constraint(equalToConstant: 42).isActive = true
ratingsView.centerXAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerXAnchor).isActive = true
ratingsView.centerYAnchor.constraint(equalTo: view.safeAreaLayoutGuide.centerYAnchor).isActive = true

Latest podspec

{
    "name": "SwiftyRatingsView",
    "version": "1.0.9",
    "license": "MIT",
    "summary": "A simple ratings view.",
    "homepage": "https://github.com/crashoverride777/swifty-ratings-view",
    "social_media_url": "http://twitter.com/overrideiactive",
    "authors": {
        "Dominik": "[email protected]"
    },
    "requires_arc": true,
    "platforms": {
        "ios": "11.4"
    },
    "source": {
        "git": "https://github.com/crashoverride777/swifty-ratings-view.git",
        "tag": "1.0.9"
    },
    "source_files": "SwiftyRatingsView/**/*.{swift}",
    "resource_bundles": {
        "SwiftyRatingsView": [
            "SwiftyRatingsView/Source/**/*.{png,jpeg,jpg,storyboard,xib,xcassets}"
        ]
    }
}

Pin It on Pinterest

Share This