Code Monkey home page Code Monkey logo

dlstarrating's Introduction

DLStarRating

A UIControl subclass that behaves similarly as the App Store rating control.

Written by David Linsin, January 2011.

Usage

You find all the sources include two sample images under DLStarRating. Add the source folder to your project and use the DLStarRatingControl in Interface Builder to setup a default 5 star rating control.

If you'd like to instantiate it yourself with a custom number of stars use:

// setup a control with 3 fractional stars at a size of 320x230
DLStarRatingControl *ratingControl = [[DLStarRatingControl alloc] initWithFrame:CGRectMake(0, 0, 320, 230) andStars:3 isFractional:YES];

You can set a default value by setting ratingControl.rating=2.5 and hook up a DLStarRatingDelegate to get notified when the user has changed the rating. Note: if you want to use fractional stars, you have to provide images with width divisible by 10.

To customize the stars, simply replace star.png/[email protected] and star_highlighted.png/[email protected] under images.

DLStarView.h lets you customize the area below the stars, detecting touches. Simply change the value of kEdgeInsetBottom to increase the area or make it smaller, in case you have other user interface components below. The default is 20px, which allows to select/deselect the stars, while still being able to see them above your finger.

DLStarRating should work with iOS 3.0+, but it has not been tested yet.

Demo

You can open the DLStarRating demo project in XCode and run it on your iPhone as well as in the Simulator. There's a DLStarRatingControl hooked up in DLStarRatingDemo.xib, as well as in DLStarRatingDemoViewController. It also shows how to set a rating value and use DLStarRatingDelegate.

Issues and Feature Requests

Please report issues via GitHub's issue tracker.

ARC

There's an ARC branch which you can use if your App uses the latest&greatest. It'll sooner or later find it's way into master.

UI Testing

The folder features contains the testing setup needed to run UI tests with zucchini.

License

DLStarRating is licensed under the Eclipse Public License.

dlstarrating's People

Contributors

dlinsin avatar kuchmiyalex avatar martinjuhasz avatar tvon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

dlstarrating's Issues

Upgrade to ARC

Upgrade source and demo to use ARC. Support both ARC and prehistoric versions.

fractional star

Is there a plan to add support for displaying a half rating? eg. a rating of 3.5?

Adopt tests

Fractional support introduced in #7 broke the zucchini tests, they need to be fixed!

How to set rater to read-only?

Greetings,

I'm trying to set the rater to read-only.

I have it set up so that the user can rate, but then I want to show them the DLStarRating read-only.

How to do this?

Many thanks in advance,

DLStarRatingControl

On DLStarRatingControl.m line 23, you wrote :

highlightedStar = [[UIImage imageNamed:@"star_highlighted"] retain];        

You forgot the extension ".png" ;)

Delegate not called sometimes

Hi,

I have used this in Table view's row. Sometime it doesn't recognised the touch and newRating method not get called. It happens sometimes.

Still stars will be highlighted.

Any suggestions ?

Error with DLStarRating Delegate

Below there is an error with the IBOutlet DLStarRating Delegate. it points to the protocol method at the bottom of the page and newRating as the problem. Not sure what that's all about?

import <UIKit/UIKit.h>

define kDefaultNumberOfStars 5

define kNumberOfFractions 10

@protocol DLStarRatingDelegate;

@interface DLStarRatingControl : UIControl {
int numberOfStars;
int currentIdx;
UIImage star;
UIImage *highlightedStar;
*__IBOutlet id delegate;
**

// ! Existing instance variable 'delegate' for property 'delegate' with assign attribute must be _unsafe_unretained
//
BOOL isFractionalRatingEnabled;
}

  • (id)initWithFrame:(CGRect)frame;
  • (id)initWithFrame:(CGRect)frame andStars:(NSUInteger)_numberOfStars isFractional:(BOOL)isFract;
  • (void)setStar:(UIImage_)defaultStarImage highlightedStar:(UIImage_)highlightedStarImage;
  • (void)setStar:(UIImage_)defaultStarImage highlightedStar:(UIImage_)highlightedStarImage atIndex:(int)index;

@Property (retain,nonatomic) UIImage *star;
@Property (retain,nonatomic) UIImage *highlightedStar;
@Property (nonatomic) float rating;
@Property (assign,nonatomic) id delegate;
@Property (nonatomic,assign) BOOL isFractionalRatingEnabled;

@EnD

@protocol DLStarRatingDelegate

-(void)newRating:(DLStarRatingControl *)control :(float)rating;

@EnD

AutoLayout bug

Hey u there? In AutoLayout the star didn't resize, and I fixed by this:
image

I saw you have stoped to maintain this project?

DLStarRatingControl Cannot be hidden

Using follow code the create the stars

customNumberOfStars = [[DLStarRatingControl alloc] initWithFrame:CGRectMake(75, 198, 240, 59) andStars:5 isFractional:YES];
customNumberOfStars.delegate = self;
customNumberOfStars.backgroundColor = [UIColor clearColor];
customNumberOfStars.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin;
customNumberOfStars.rating = [self.annotation rate];
[self.view addSubview:customNumberOfStars];

tried [customNumberOfStars setHidden:NO]; and [customNumberOfStars removeFromSuperview];
both method cannot hidden the stars from view

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.