Rating stars for the iphone

后端 未结 4 693
野趣味
野趣味 2020-12-17 05:03

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 comp

相关标签:
4条回答
  • 2020-12-17 05:28

    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.

    0 讨论(0)
  • 2020-12-17 05:29

    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;
        }
    }
    
    0 讨论(0)
  • 2020-12-17 05:36

    Another way you may try DLStarRating lets you customize the area below the stars, detecting touches.

    enter image description here

    0 讨论(0)
  • 2020-12-17 05:38

    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.

    0 讨论(0)
提交回复
热议问题