Monday, June 6, 2011

Integrate Rating feature now easily !

Ah ! Back to blogging after quite sometime...hmmm good..
Ok.. I just wrote a code which can be used  by coders if they are using rating feature in their app.
Its a completely customizable code. In MainViewController.

    float _width=320;//can be anything, it will rearrage itself properly when it really draws
    float _height=320;//can be anything, it will rearrage itself properly when it really draws
    StarObject *myStarRatingView=[[StarObject alloc]initWithFrame:CGRectMake(10, 100, _width, _height)];
    [myStarRatingView setBackgroundColor:[UIColor whiteColor]];
    myStarRatingView.starBoundRect=CGRectMake(0, 0, 23, 23);
    myStarRatingView.selectedStar=[UIImage imageNamed:@"selectedStar.png"];
    myStarRatingView.unselectedStar=[UIImage imageNamed:@"unselectedStar.png"];
    [self.view addSubview:myStarRatingView];

Ok. So this is the piece of code where you can do all the changes....
selectedStar is the image which will be displayed  when star is selected and unselectedStar  is the image which will be displayed when star is unselected. You can change the size of the star image which will be displayed with starBoundRect and if you want to change the number of stars being displayed, just change the value of numberOfStars everything else will be automatically taken care of. Following is a screen capture .


  1. Why not use retain properties so you don't need to retain UIImages in that way? Hard to remember to release those images before releasing the StarObject. It would be the right way...

  2. Thanks for noticing. Fixed it.