Simple star rating view for iOS written in Objective-C

Overview

HCSStarRatingView

HCSStarRatingView is a UIControl subclass to easily provide users with a basic star rating interface.

It supports all device resolutions and although it requires no images to render the stars (thanks PaintCode), you can provide custom ones if you so desire.

Installation

Carthage

github "hsousa/HCSStarRatingView"

CocoaPods

use_frameworks!

(...)

pod 'HCSStarRatingView', '~> 1.5'

and run pod install

Manually

You can also install it manually by copying HCSStarRatingView.{h|m} into your project or including the project in your own project/workspace, similar to what's being done in Sample.

Usage

Programatically

Create a new instance and set the properties you desire to customize.

HCSStarRatingView *starRatingView = [[HCSStarRatingView alloc] initWithFrame:CGRectMake(50, 200, 200, 50)];
starRatingView.maximumValue = 10;
starRatingView.minimumValue = 0;
starRatingView.value = 0;
starRatingView.tintColor = [UIColor redColor];
[starRatingView addTarget:self action:@selector(didChangeValue:) forControlEvents:UIControlEventValueChanged];
[self.view addSubview:starRatingView];

HCSStarRatingView also works great with Auto Layout, so feel free to set some constraints instead of just giving it a frame (check sample project)!

Half-star ratings:

starRatingView.allowsHalfStars = YES;
starRatingView.value = 2.5f;

Enable accurateHalfStars to get more precise ratings (works with images too)!

starRatingView.accurateHalfStars = YES;

Custom images:

Using custom images in HCSStarRatingView is as easy as setting a property. You only need to set emptyStarImage and filledStarImage, but you can also provide the half image to halfStarImage, if your design requires you to:

starRatingView.emptyStarImage = [UIImage imageNamed:@"heart-empty"];
starRatingView.halfStarImage = [UIImage imageNamed:@"heart-half"]; // optional
starRatingView.filledStarImage = [UIImage imageNamed:@"heart-full"];

If you want to use template images programatically, just make sure they have the proper Rendering Mode:

starRatingView.emptyStarImage = [[UIImage imageNamed:@"heart-empty"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
starRatingView.halfStarImage = [[UIImage imageNamed:@"heart-half"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; // optional
starRatingView.filledStarImage = [[UIImage imageNamed:@"heart-full"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];

Interface Builder

HCSStarRatingView also implements IB_DESIGNABLE and IBInspectable so you can fully customize it in Interface Builder.

PS: In order to use template images in Interface Builder you must go to that image's properties in your Asset Catalog and change the Render As setting to Template Image.

Accessibility

Users with specific needs should be able to fully read and interact with HCSStarRatingView, since it fully supports VoiceOver.

If you or your users have other specific needs and you're having issues with this control, please contact me so we can figure it out! :-)

Contact

Hugo Sousa

License

HCSStarRatingView is available under the MIT license. See the LICENSE file for more info.

Comments
  • Error with preview in storyboard

    Error with preview in storyboard

    Within Xcode 7.0.1 I get the following error in the storyboard:

    file:///../Main.storyboard: error: IB Designables: Failed to update auto layout status: The bundle “$(PRODUCT_NAME)” couldn’t be loaded because its executable couldn’t be located.
    

    And there is no preview of the component

    opened by ylecuyer 19
  • bitcode problem

    bitcode problem

    i got this error, “HCSStarRatingView.framework/HCSStarRatingView' was built without full bitcode. All frameworks and dylibs for bitcode must be generated from Xcode Archive or Install build for architecture armv7 clang: error: linker command failed with exit code 1 (use -v to see invocation)” please support bitcode

    bug 
    opened by iVanPan 16
  • Custom Image

    Custom Image

    Hi, bro

    I have a problem with RatingView that u posted on Github.

    I applied the following source to use a different image, not the existing star image, as you wrote.

    starRatingView.emptyStarImage = [UIImage imageNamed:@"heart-empty"]; //like_off_big.png starRatingView.filledStarImage = [UIImage imageNamed:@"heart-full"];//like_on_big.png

    I could see the new image that I put in on RatingView, but when I tried to run RatingView, apps crash. (touched RatingView)

    The reason for the crash is

    [UIImage renderingMode]: message sent to deallocated instance

    I used call stack and figured out the following code occurred the error.

    [self _drawStarWithFrame:frame tintColor:self.tintColor highlighted:highlighted]; in drawRect:(CGRect)rect

    Could you please let me know how to solve this problem?

    Thank you.

    opened by kyominoh 7
  • How to setup HCSStarRatingView view in UICollection view cell Swift?

    How to setup HCSStarRatingView view in UICollection view cell Swift?

    Hello friends, I am having problem using HCSStarRatingView in UICollection Cell. How to setup HCSStarRatingView view in UICollection view cell Swift 3? HCSStarRatingView star value set keeps on changing when rating view in UICollectionView Cell and collection view is scrolled.

    I added HCSStarRatingView on UICollection View Cell in storyboard. Created strong outlet of HCSStarRatingView as

    @IBOutlet var ratingView: HCSStarRatingView!

    Then in collection view cell for index path code is like this.

    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {

    let cell = self.collectionVC.dequeueReusableCell(withReuseIdentifier: "collectionCell", for: indexPath as IndexPath) as! CustomCollectionViewCell

    cell.ratingView.value = (self.ratingValueDataArray.value(forKey: "rating") as AnyObject).object(at:indexPath.row) as! CGFloat // setting rating value from JSON array response. return cell

    }

    However, for first time value is set on rating view correctly. But on collection view scroll the value is changed on random manner.

    Any help?

    Thanks

    opened by PrakashMaharjan 6
  • allow stars to be unselected

    allow stars to be unselected

    This is not meant to be a final PR, but a point of discussion. This code works and allows stars to be unselected. Maybe the only point of contention is the setting of '0' to be the 'unselected' value. I figure we do this since even the 'minimumValue' takes a max of 0 and _minimumValue. Let me know your thoughts. Thanks for the library!

    opened by brightredchilli 6
  • Interface Designer does not render the view

    Interface Designer does not render the view

    It throws the following error:

    Main.storyboard: error: IB Designables: Failed to render instance of HCSStarRatingView: Failed to load designables from path (null)
    

    I use the view with the following settings:

    What could be the problem? How can I solve it?

    opened by gklka 6
  • Added star empty state color, border color and border width

    Added star empty state color, border color and border width

    This will allow to change the empty state color, so we will be able use separate colors for star fill state and empty state. In addition star border color and width properties are also configurable through IBInspectable. This will cover most of the UI variations if you want to stick with stars for rating.

    screen shot 2016-11-04 at 4 01 28 pm

    screen shot 2016-11-04 at 4 01 51 pm

    opened by irfangul92 5
  • Got error

    Got error "IB Designables: Failed to update auto layout status" when adding to storyboard.

    Installed via Cocoapods 0.37.2. Xcode 6.4.

    There are 2 red errors shows up on the left side of Xcode. I can build and run the app but the page that has this view goes blank.

    • xxx/Driver.storyboard: error: IB Designables: Failed to update auto layout status: Failed to load designables from path (null)
    • xxx/Driver.storyboard: error: IB Designables: Failed to render instance of HCSStarRatingView: Failed to load designables from path (null)

    Btw, I didn't use use_frameworks! in the Podfile. Is it required?

    opened by hlung 5
  • Add Podspec and note about installation to Readme

    Add Podspec and note about installation to Readme

    I kinda guessed at the iOS version support, I put >= 6.0 in the Podspec. If you decide to keep this, it would be great if you could tag the library and update the version line to match the tag.

    Note: I haven't made a podspec before, this was essentially copied from another project and modified to fit yours.

    opened by ScottWarner 5
  • Star rating in tableview do not show the rating value properly

    Star rating in tableview do not show the rating value properly

    Hello sir, I have added the star rating view in my app. But i have an issue if i use the star rating in view controller its working fine but if i use this in a table view for multiple rows then the rating is not show properly. if i scroll the tableview the value of upper cells that contains rating view is changed. Please suggest me what can i do to implement it in tableview??

    opened by Gurmeetkaur5949 4
  • Ibdesignable not working correctly through Carthrage.

    Ibdesignable not working correctly through Carthrage.

    There seems to be a issue when trying to preview the view with the framework using carthage. Mine fails to render and complains that the target is missing.

    opened by phongleq 3
  • Accessibility: how to give rating with VoiceOver?

    Accessibility: how to give rating with VoiceOver?

    When HCSStarRatingView is tested with VoiceOver and accessibility enabled, it only reads the current value of rating and passes to the next element. I want visually impaired users to be able to select the 1st star, 2nd star and so on. while VoiceOver focuses on each star one by one and allows user to select it and give rating. Is it possible?

    opened by alierdogan7 0
  • Allow change in star shape programmatically

    Allow change in star shape programmatically

    Allows change in star shape programmatically by overriding the - (void)_drawAccurateHalfStarShapeWithFrame:(CGRect)frame tintColor:(UIColor *)tintColor progress:(CGFloat)progress { method

    opened by jwolkovitzs 0
  • Failed to render and update auto layout status

    Failed to render and update auto layout status

    file:///Users/admin/Desktop/untitled%20folder/ecommerce/eShop/Base.lproj/Main.storyboard: error: IB Designables: Failed to render and update auto layout status for ProductViewController (aZt-IO-q4U): Failed to load designables from path (null)

    Due to this issue I am unable to submit this app to App store.

    opened by rahulsingh1101 2
  • [Request]Support Editing Changed and other events

    [Request]Support Editing Changed and other events

    I hope this library could support other event instead of only ValueChanged. It help we build better UI/UX. When user swipe their finger over the rating bar, we can display a description for each value:

    1. Oops! too bad
    2. Not good enough
    3. Good .... and so on

    That is my idea.

    BR

    opened by purepure 0
  • Is it Possible to Use different Tint Color on Unselected Image?

    Is it Possible to Use different Tint Color on Unselected Image?

    Im Trying to Make a Star Rating. and Using an AlertController to do so. With the Selected Star Color Yellow. but the unSelected Star would be outline as yellow too but this will make it less visible. if only can make it DarkGray for unselected Star. Please any help would do

    opened by Cruzv35 0
Owner
Hugo Sousa
👨‍💻 iOS/tvOS at @plexinc | ❤️ Husband | 🐕🐈 Pet lover | 🤓 Geek | 🤤 Caramel enthusiast.
Hugo Sousa
A simple and configurable rating/favorite view.

ImageRating A simple and configurable rating/favorite view. ImageRating will display a sequence of SFSymbols from 0-maxImages in half or whole increme

Ferdinand G Rios 0 Dec 24, 2021
An emoji-liked rating view for iOS, implemented in Swift3.

TTGEmojiRate An emoji-liked rating view for iOS, implemented in Swift3. Android version: PeterSmileRate by SilicorniO. Great work ! :) Inspired by Rat

zekunyan 289 Jun 13, 2022
Whole, half or floating point ratings control written in Swift

FloatRatingView A simple rating view for iOS written in Swift! Supports whole, half or floating point values. I couldn't find anything that easily set

Glen Yi 546 Dec 8, 2022
StarryStars is iOS GUI library for displaying and editing ratings

StarryStars StarryStars is iOS GUI library for displaying and editing ratings Features StarryStars' RatingView is both IBDesignable and IBInspectable

Peter Prokop 175 Nov 19, 2022
A modern utility that reminds your iOS app's users to review the app in a non-invasive way.

SiriusRating A modern utility that reminds your iOS app's users to review the app in a non-invasive way. Features SwiftUI and UIKit support Configurab

The App Capital 5 Sep 24, 2022
A star rating control for iOS/tvOS written in Swift

Cosmos, a star rating control for iOS and tvOS This is a UI control for iOS and tvOS written in Swift. It shows a star rating and takes rating input f

Evgenii Neumerzhitckii 2.1k Dec 28, 2022
A simple star rating library for SwiftUI apps on macOS and iOS

DLDRating A simple star rating library for SwiftUI apps on macOS and iOS. Features Installation Usage Styling Credits DLDRating was made by Dionne Lie

null 1 Mar 6, 2022
A simple and configurable rating/favorite view.

ImageRating A simple and configurable rating/favorite view. ImageRating will display a sequence of SFSymbols from 0-maxImages in half or whole increme

Ferdinand G Rios 0 Dec 24, 2021
An emoji-liked rating view for iOS, implemented in Swift3.

TTGEmojiRate An emoji-liked rating view for iOS, implemented in Swift3. Android version: PeterSmileRate by SilicorniO. Great work ! :) Inspired by Rat

zekunyan 289 Jun 13, 2022
Flix is a film rating application for iOS.

Flix is a film rating application for iOS.

Yijie Guo 0 Nov 20, 2021
JSPatch bridge Objective-C and Javascript using the Objective-C runtime. You can call any Objective-C class and method in JavaScript by just including a small engine. JSPatch is generally used to hotfix iOS App.

JSPatch 中文介绍 | 文档 | JSPatch平台 请大家不要自行接入 JSPatch,统一接入 JSPatch 平台,让热修复在一个安全和可控的环境下使用。原因详见 这里 JSPatch bridges Objective-C and JavaScript using the Object

bang 11.4k Jan 1, 2023
iOS App that browse the people from Star Wars Universe using GraphQL Api.

Ravn-Challenge-V2--OscarCastillo- iOS App that browse the people from Star Wars Universe using GraphQL Api. This project uses Apollo swift Client. htt

Oscar Castillo 4 Jun 9, 2021
Lambton College, 2nd Semester Final IOS Project (Star Wars) game

The game we developed for our project of the course advanced iOS application is based on a functioning of a real time shooting game, in which initiall

Suraj Devgan 6 Aug 18, 2022
Fetch the star wars api from all the planets and list and show details using Swift UI and Combine

Star Wars Planets Fetch the star wars planet data by using stat war api, list and show details using SwiftUI and Combine frameworks ?? Swift UI Framew

null 1 Aug 10, 2022
A Star Wars themed card game designed to see if you know your sith vs jedi

StarWarsCardGame A Star Wars themed card game designed to see if you know your sith vs jedi. Learning Objectives: Alert Controllers, Protocol/Delegate

Jonathan Llewellyn 0 Nov 29, 2021
:star: Custom card-designed CollectionView layout

CardsLayout CardsLayout is a lightweight Collection Layout. Installation CocoaPods You can use CocoaPods to install CardsLayout by adding it to your P

Filipp Fediakov 798 Dec 28, 2022
This sample app use the Star Wars public api to show a list of characters

StarWars-MVVM In this sample app, I use the Star Wars public api to show a list of characters from the Star Wars movie series. There are two goals I w

Paul O'Neill 1 Mar 8, 2022
Beautiful animated Login Alert View. Written in Objective-C

UIAlertView - Objective-C Animated Login Alert View written in Swift but ported to Objective-C, which can be used as a UIAlertView or UIAlertControlle

Letovsky 2 Dec 22, 2021
MyLayout is a simple and easy objective-c framework for iOS view layout

MyLayout is a powerful iOS UI framework implemented by Objective-C. It integrates the functions with Android Layout,iOS AutoLayout,SizeClass, HTML CSS float and flexbox and bootstrap. So you can use LinearLayout,RelativeLayout,FrameLayout,TableLayout,FlowLayout,FloatLayout,PathLayout,GridLayout,LayoutSizeClass to build your App 自动布局 UIView UITableView UICollectionView RTL

欧阳大哥2013 4.2k Dec 30, 2022
SSToastMessage is written purely in SwiftUI. It will add toast, alert, and floating message view over the top of any view. It is intended to be simple, lightweight, and easy to use. It will be a popup with a single line of code.

SSToastMessage SSToastMessage is written in SwiftUI. It will add toast, alert, and floating message view over the top of any view. It is intended to b

Simform Solutions 223 Dec 2, 2022