12

In Google groups and some other web sites, there is a 5-star rating component which is pretty neat, such as in this url: http://groups.google.com/group/Google-Picasa-Data-API/browse_thread/thread/b5a346e6429a70a7?hl=en

I am wondering whether there is an existing 5-star rating component in the iPhone environment. Or if there is not, if anyone has clue where to start?

Thanks

Chris Hanson
  • 54,380
  • 8
  • 73
  • 102
BlueDolphin
  • 9,765
  • 20
  • 59
  • 74

8 Answers8

14

Here's another open source solution: https://github.com/dlinsin/DLStarRating

dlinsin
  • 19,249
  • 13
  • 42
  • 53
6

UIView that allows you to build Rating components to provide the same kind of experience AppStore or Youtube applications on iPhone do.

http://code.google.com/p/s7ratingview/

Aleks N.
  • 6,051
  • 3
  • 42
  • 42
  • 1
    The s7ratingview is shifted on GitHub - http://github.com/eisernWolf/TouchCustoms – Sagar Oct 08 '10 at 04:58
  • 1
    It is here now : http://code.google.com/p/s7ratingview/downloads/detail?name=s7ratingview-basic-release.zip – Stefan H Jan 11 '11 at 04:04
5

I'd go simpler. Subclass UIControl and implement the touchesBegan: touchesMoved: and touchesEnded: methods. You can determine which star the user pressed/dragged/let up on with the X coordinate of the touch. For example:

CGFloat relativeTouchLocation = [event locationInView:self] / self.bounds.size.width;

Then it's just up to you to determine which stars are illuminated based on that value. Oh, and to send a UIControlEventValueChanged event.

Obviously, you also override drawRect: to draw the stars in the view.

Although Jason's solution above will work, your user won't be able to slide her finger across the control to fine-tune her rating. This would also give you the option of doing half-stars or other fine adjustments.

Alex
  • 26,829
  • 3
  • 55
  • 74
4

I don't know of any free/available components off the top of my head, but if nobody offers one up and/or you can't find one you like, it should be fairly trivial to roll your own. In the simplest terms, you would only have to:

  1. Create/Find a star icon - one outline (unselected), one filled
  2. Create a UIButton and set the icons for the selected/unselected states
  3. Create a container view that held your x stars and when one was selected, the container could set the selected state on any button to the left of the touched button.

Shouldn't take long at all to build...

Jason Coco
  • 77,985
  • 20
  • 184
  • 180
3

Another selection of rating controls. These allow you to input the rating and not only view it. http://cocoacontrols.com/search?utf8=%E2%9C%93&q=rating&commit=Search

DenTheMan
  • 1,277
  • 2
  • 13
  • 21
1

I would probably implement this using a UIView with custom touchesXXX messages, so that the user could, for example, touch the first star and drag out a four-star rating. Just my $0.02.

Ben Gottlieb
  • 85,404
  • 22
  • 176
  • 172
1

As a general rule, if it's not in the Interface Builder, it's not available "for free," and you'll have to write it yourself.

When it comes to the iPhone, Apple has also provided easily understood sample code that shows off every single available component and how to use them. If you don't see it in their code, you have to build it yourself.

August
  • 12,139
  • 3
  • 29
  • 30
0

You can give DYRateView a try.

There is a tutorial on my blog on how to use DYRateView in your project: http://iappexperience.com/post/23227218867/dyrateview-a-simple-yet-powerful-rating-control-for.

picture

picture

Community
  • 1
  • 1
dyang
  • 166
  • 1
  • 3