Giter Site home page Giter Site logo

cosmos's Introduction

Cosmos, a star rating control for iOS

[Carthage compatible][carthage] [CocoaPods Version][cocoadocs] License [Platform][cocoadocs] [cocoadocs]: http://cocoadocs.org/docsets/Cosmos [carthage]: https://github.com/Carthage/Carthage

Cosmos, star rating control for iOS / Swift

This is a UI control for iOS 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.
  • 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)

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'

Setup in Xcode 6 / Swift 1.2 project

Cosmos is written in Swift 2.0 and requires Xcode 7. Use the previous version of the library in Xcode 6 projects. Thanks to nickhart for making the Xcode 6 version.

Usage

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

Add view control in attributes inspector

  1. 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

  1. Customize the Cosmos view appearance in the Attributes Inspector.

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)"

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

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

// 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.colorFilled = UIColor.orangeColor()

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

// Change the rating when the view is touched
cosmosView.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

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.

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.