I have been looking for a 5-Star rating control for a while now and have not found a solid solution.
This question:
Anyone know whether there is a 5-star rating component on iPhone?
Provided a couple of links to projects which are no longer available, and i have not been able to track them down.
Edit: I am apparently bad at tracking down projects, but I think part of my question still stands. Here is the updated link http://code.google.com/p/s7ratingview/downloads/detail?name=s7ratingview-basic-release.zip
So this questions is 2 part - Is there a solid premade solution out there, and could you direct me to it?
Is it better / fairly easy to (yes, i realize these two facets are in conflict) grow my own solution? Could you give me some tips/resources to do so. I understand the basic idea of subclassing UIView and tracking touch events to expand an image ontop of another image to look like stars, but a little more direction would be helpful. I have been developing on the iphone for a little under a week and still need a bit of hand-holding.
Try Ray Wenderlich's custom UIView with a 5-star rating.
[EDIT]
You can also try using UISlider and supplying a minimum/maximum track images.
You can give DYRateView a try. I wanted to reuse the one in Ray's tutorial as much as possible, but there were several features missing from it, so I made one myself.
You can check out my blog for further details on how to use DYRateView in your project: http://iappexperience.com/post/23227218867/dyrateview-a-simple-yet-powerful-rating-control-for.
Another way you may try DLStarRating lets you customize the area below the stars, detecting touches.
Just Easy to Give a Star Follow this Code and Copy and Paste into Your Project and Simply Run.
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
startview = [[UIView alloc] initWithFrame:CGRectMake(45, 70, 230, 50)];
startview.backgroundColor = [UIColor redColor];
NSInteger getrating = 0;
int x = 5;
for (int k = 1; k <= 5; k++)
{
UIImageView * mystarimage = [[UIImageView alloc] initWithFrame:CGRectMake(x, 5, 40, 40)];
if (getrating >= k)
{
mystarimage.image = [UIImage imageNamed:@"star.png"];
}
else
{
mystarimage.image = [UIImage imageNamed:@"gray-star.png"];
}
mystarimage.tag = k;
mystarimage.userInteractionEnabled = YES;
[startview addSubview:mystarimage];
UITapGestureRecognizer *letterTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(updateStar:)];
rateMember = mystarimage.tag;
NSLog(@"rateing %ld",(long)rateMember);
letterTapRecognizer.numberOfTapsRequired = 1;
[mystarimage addGestureRecognizer:letterTapRecognizer];
x = x + 45;
}
[self.view addSubview:startview];
}
-(void)updateStar :(UITapGestureRecognizer*)sender
{
UIView *view = sender.view;
NSLog(@"hello ji %ld", (long)view.tag);
NSInteger getrating;
switch (view.tag)
{
case 1:
NSLog(@"press 1");
rateMember = 1;
break;
case 2:
NSLog(@"press 2");
rateMember = 2;
break;
case 3:
NSLog(@"press 3");
rateMember = 3;
break;
case 4:
NSLog(@"press 4");
rateMember = 4;
break;
case 5:
NSLog(@"press 4");
rateMember = 5;
break;
default:
NSLog(@"press 5");
rateMember = 5;
break;
}
getrating = rateMember;
NSLog(@"Get rating -------> %ld",(long)getrating);
int x = 5;
for (int k = 1; k <= 5 ; k++)
{
UIImageView * mystarimage = [[UIImageView alloc] initWithFrame:CGRectMake(x, 5, 40, 40)];
if (getrating >= k)
{
mystarimage.image = [UIImage imageNamed:@"star.png"];
}
else
{
mystarimage.image = [UIImage imageNamed:@"gray-star.png"];
}
mystarimage.tag = k;
mystarimage.userInteractionEnabled = YES;
[startview addSubview:mystarimage];
UITapGestureRecognizer *letterTapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(updateStar:)];
letterTapRecognizer.numberOfTapsRequired = 1;
[mystarimage addGestureRecognizer:letterTapRecognizer];
x = x + 45;
}
}