Skip to content
forked from evgenyneu/Cosmos

A star rating control for iOS/tvOS written in Swift

License

Notifications You must be signed in to change notification settings

tayyabejaz/Cosmos

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔨🔨🔨 This is work in progress 🔨🔨🔨

Cosmos, a star rating control for iOS / Swift

Star raiting control for iOS / Swift

This is a UI control for iOS for showing a 5-star rating or taking the rating input from the user. Cosmos is a subclass of a UIView.

  • Shows star rating with an optional text label.
  • Can be used as a rating input control.
  • Cosmos view can be customized in the Storyboard without writing code.
  • Includes different star filling modes: full, half-filled and precise.

Binary star system of Sirius A and Sirius B (artist's impression)

We are a way for the cosmos to know itself.

Carl Sagan, Cosmos.

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

Setup

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

Add source (iOS 7+)

Simply add CosmosDistrib.swift file into your Xcode project.

Setup with Carthage (iOS 8+)

Alternatively, add github "exchangegroup/Cosmos" ~> 1.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!
pod 'Cosmos', '~> 1.0'

Usage

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

  2. Add View control into your storyboard. Set its class to CosmosView in the identity inspector. Set its module property to Cosmos if you did Carthage or CocoaPods setup.

  3. Customize the Cosmos view appearance in the attributes inspector.

Add Cosmos rating view to the storyboard

Customize cosmos appearance in the attributes inspector in Xcode.

Using Cosmos in code

You can also style and control the Cosmos view from your code by creating an outlet in your view controller or by creating a new instance of CosmosView class.

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

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

// Receive user input
view.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.

// Show only fully filled stars
view.settings.fillMode = .Full

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

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

// Set the color of a filled star
view.settings.colorFilled = UIColor.orangeColor()

// Set the border color of an empty star
view.settings.borderColorEmpty = UIColor.orangeColor()

// Change the rating when the view is touched
view.settings.updateOnTouch = true

Demo app

This project includes a demo iOS app.

five star rating control for iOS written in Swift

Alternative solutions

Here are some other star rating controls for iOS:

License

Star is released under the MIT License.

About

A star rating control for iOS/tvOS written in Swift

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 96.7%
  • Shell 1.6%
  • Other 1.7%