Skip to content

R-H-T/StarRatingView

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

StarRatingView

A Dynamic Star Rating View in Pure Swift by R-H-T


Getting Started

This view can be initialized either by code or be included in your storyboard or nib.

In Code:

    
    // MARK: - Methods
    
    fileprivate func setupStarRatingView() {
        
        let starRatingView = StarRatingView(starCount: 5, rating: 5)
        
        view.addSubview(starRatingView)
        
        starRatingView.hasDropShadow = true
        
        starRatingView.translatesAutoresizingMaskIntoConstraints = false
        
        NSLayoutConstraint.activate([
            starRatingView.centerYAnchor.constraint(equalTo: view.centerYAnchor, constant: 0),
            starRatingView.heightAnchor.constraint(equalToConstant: 48),
            starRatingView.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: 0),
            starRatingView.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: 0)
            ])
        
        self.starRatingView = starRatingView
    }
    

For Storyboards:

// ViewController.swift
    
    /* ... */

    // MARK: - Properties
    
    // MARK: Outlets
    @IBOutlet weak var starRatingView: StarRatingView!

    /* ... */

    // MARK: - Lifecycle
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        starRatingView.hasDropShadow = true
        starRatingView.updateView(rating: 4.5)
    }

Images

You'll need to provide three images in your assets folder representing each of the star's 3 main states (emptyStar, halfStar, filledStar). Note that the images must be somewhat clean and simple, because they will be rendered as templates by default and tinted to UIColor.yellow.


License

TBD (To be determined)

Copyright © 2018 Roberth Hansson-Tornéus. All rights reserved.

About

A Dynamic Star Rating View in Pure Swift by R-H-T

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages