Anyone know whether there is a 5-star rating component on iPhone?

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


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/


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


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.