Latest 9.0.0
Homepage https://github.com/marketplacer/Cosmos
License MIT
Platforms ios 8.0, tvos 9.0
Authors

Cosmos, a star rating control for iOS and tvOS

Carthage compatible
CocoaPods Version
License
Platform

Cosmos, star rating control for iOS / Swift

This is a UI control for iOS and tvOS written in Swift. It shows a star rating and takes rating input from the user. Cosmos is a subclass of a UIView that will allow your users post those inescapable 1-star reviews!

  • Shows star rating with an optional text label.
  • Can be used as a rating input control (iOS only).
  • Cosmos view can be customized in the Storyboard without writing code.
  • Includes different star filling modes: full, half-filled and precise.
  • Cosmos is accessible and works with voice-over.
  • Supports right-to-left languages.

<img src=’https://raw.githubusercontent.com/marketplacer/Cosmos/master/graphics/Drawings/1280px-Sirius_A_and_B_artwork.jpg
alt="Binary star system of Sirius A and Sirius B (artist’s impression)" width=’450’>

Picture of binary star system of Sirius A and Sirius B by NASA, ESA and G. Bacon (STScI). Source: spacetelescope.org.

Setup (Swift 3.0 / Xcode 8)

There are three ways you can add Cosmos to your Xcode project.

Add source (iOS 8+)

Simply add CosmosDistrib.swift file into your Xcode project.

Setup with Carthage (iOS 8+)

Alternatively, add github "marketplacer/Cosmos" ~> 9.0 to your Cartfile and run carthage update.

Setup with CocoaPods (iOS 8+)

If you are using CocoaPods add this text to your Podfile and run pod install.

use_frameworks!
target 'Your target name'
pod 'Cosmos', '~> 9.0'

Legacy Swift versions

Setup a previous version of the library if you use an older version of Swift.

Usage

1) Drag View object from the Object Library into your storyboard.

Add view control in attributes inspector

2) Set the view’s class to CosmosView in the Identity Inspector. Set its module property to Cosmos if you used Carthage or CocoaPods setup methods.

Add Cosmos rating view to the storyboard

tvOS note: read the collowing setup instructions for tvOS if you see build errors at this stage.

3) Customize the Cosmos view appearance in the Attributes Inspector. If storyboard does not show the stars click Refresh All Views from the Editor menu.

Customize cosmos appearance in the attributes inspector in Xcode.

Note: Carthage setup method does not allow to customize Cosmos view from the storyboard, please do it from code instead.

Using Cosmos in code

Add import Cosmos to your source code if you used Carthage or CocoaPods setup methods.

You can style and control Cosmos view from your code by creating an outlet in your view controller. Alternatively, one can instantiate CosmosView class and add it to the view manually without using Storyboard.

// Change the cosmos view rating
cosmosView.rating = 4

// Change the text
cosmosView.text = "(123)"

// Called when user finishes changing the rating by lifting the finger from the view.
// This may be a good place to save the rating in the database or send to the server.
cosmosView.didFinishTouchingCosmos = { rating in }

// A closure that is called when user changes the rating by touching the view.
// This can be used to update UI as the rating is being changed by moving a finger.
cosmosView.didTouchCosmos = { rating in }

Customization

One can customize Cosmos from code by changing its settings. See the Cosmos configuration manual for the complete list of configuration options.

// Do not change rating when touched
// Use if you need just to show the stars without getting user's input
cosmosView.settings.updateOnTouch = false

// Show only fully filled stars
cosmosView.settings.fillMode = .full
// Other fill modes: .half, .precise

// Change the size of the stars
cosmosView.settings.starSize = 30

// Set the distance between stars
cosmosView.settings.starMargin = 5

// Set the color of a filled star
cosmosView.settings.filledColor = UIColor.orange

// Set the border color of an empty star
cosmosView.settings.emptyBorderColor = UIColor.orange

// Set the border color of a filled star
cosmosView.settings.filledBorderColor = UIColor.orange

Using Cosmos in a scroll/table view

Here is how to use Cosmos in a scroll view or a table view.

Using Cosmos settings from Objective-C

This manual describes how to set/read Cosmos settings in Objective-C apps.

Demo app

This project includes a demo iOS app.

Five star rating control for iOS written in Swift

Using cosmos in a table view

Using cosmos in a table view

Version 1.2 upgrade guide

Please refer to the changelog instructions to upgrade from versions of Cosmos prior to 1.2.

Alternative solutions

Here are some other star rating controls for iOS:

Thanks 👍

We would like to thank the following people for their valuable contributions.

License

Cosmos is released under the MIT License.

🌌⭐️🌕🚀🌠

We are a way for the cosmos to know itself.

Carl Sagan, from 1980 "Cosmos: A Personal Voyage" TV series.

Latest podspec

{
    "name": "Cosmos",
    "version": "9.0.0",
    "license": {
        "type": "MIT"
    },
    "homepage": "https://github.com/marketplacer/Cosmos",
    "summary": "5-star rating control written in Swift",
    "description": "This is a UI control for iOS and tvOS that shows a 5-star rating or takes rating input from the user. Cosmos is a subclass of a UIView. Let your users see and post beautiful 3-star reviews!nn* Shows star rating with an optional text label.n* Can be used as a rating input control (iOS only).n* Cosmos view can be customized in the Storyboard without writing code.n* Includes different star filling modes: full, half-filled and precise.n* Cosmos is accessible and works with voice-over.n* Supports right-to-left languages.",
    "authors": {
        "Evgenii Neumerzhitckii": "[email protected]"
    },
    "source": {
        "git": "https://github.com/marketplacer/Cosmos.git",
        "tag": "9.0.0"
    },
    "screenshots": "https://raw.githubusercontent.com/marketplacer/Cosmos/master/graphics/Screenshots/star_screenshot_dark.png",
    "source_files": "Cosmos/**/*.swift",
    "platforms": {
        "ios": "8.0",
        "tvos": "9.0"
    },
    "pushed_with_swift_version": "3.0"
}

Pin It on Pinterest

Share This