UIView Tutorial for iOS: How To Make a Custom UIView in iOS 5: A 5 Star Rating View

Discussion of the official tutorials published on raywenderlich.com. Please only discuss the official tutorials here - for general questions, use the General Discussion forum instead.

UIView Tutorial for iOS: How To Make a Custom UIView in iOS 5: A 5 Star Rating View

Postby rwenderlich » Tue Aug 17, 2010 11:00 am

This is the official thread to discuss the following blog post: UIView Tutorial for iOS: How To Make a Custom UIView in iOS 5: A 5 Star Rating View
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
User avatar
rwenderlich
Team Member
Site Admin
 
Posts: 2155
Joined: Thu Dec 23, 2010 4:14 pm
Has thanked: 28 times
Been thanked: 338 times

Re: How To Make a Custom UIView: A 5 Star Rating View

Postby hiessu » Fri Dec 24, 2010 3:45 am

I add some code to show half-image star.
In - (void)handleTouchAtLocation:(CGPoint)touchLocation
change and add:
CGFloat distance = touchLocation.x - imageView.frame.origin.x;
if (distance <= 0) continue;
if (distance > imageView.frame.size.width / 2) {
_rating = i + 1;
break;
} else if (distance > imageView.frame.size.width / 3){
_rating = i + 0.5;
break;
}

But I'm not sure about this solution...

Good article!
hiessu
n00b
 
Posts: 2
Joined: Fri Dec 24, 2010 3:41 am
Has thanked: 0 time
Been thanked: 0 time

Re: How To Make a Custom UIView: A 5 Star Rating View

Postby rwenderlich » Fri Dec 24, 2010 4:17 am

Hm, I'm not sure if that's quite right... it looks like you're saying "if the touch is 1/2+ the way in, make it fully starred, but if it's 1/3+ the way in, make it half starred."

Instead what I would do is if the touch is 1/2-1, make it 1/2 starred, and if 1+ completely starred.
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
User avatar
rwenderlich
Team Member
Site Admin
 
Posts: 2155
Joined: Thu Dec 23, 2010 4:14 pm
Has thanked: 28 times
Been thanked: 338 times

Re: How To Make a Custom UIView: A 5 Star Rating View

Postby udledzepp » Wed Jan 05, 2011 2:07 pm

Hi Ray,
I am trying to add two table views in one controller. Now the problem is for the first one i have the delegates defined, but for the second one i don't want to use the same delegate methods . So do I need to write my own delegate for the second table view. I am trying to do the same thing but the delegate method is not getting called. Can you suggest any help.
udledzepp
n00b
 
Posts: 1
Joined: Wed Jan 05, 2011 2:03 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How To Make a Custom UIView: A 5 Star Rating View

Postby rwenderlich » Thu Jan 06, 2011 12:07 am

In the table view delegate methods, they pass you the table view that is sending you the message as a parameter. So you can look at this and do different things based on whether it's the first or the second table view.
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
User avatar
rwenderlich
Team Member
Site Admin
 
Posts: 2155
Joined: Thu Dec 23, 2010 4:14 pm
Has thanked: 28 times
Been thanked: 338 times

Re: How To Make a Custom UIView: A 5 Star Rating View

Postby Maethalion » Mon Jan 10, 2011 9:01 pm

Can't you do the same thing with a UISlider and provide custom minimum/maximum Track Images ?
Maethalion
n00b
 
Posts: 1
Joined: Mon Jan 10, 2011 9:00 pm
Has thanked: 0 time
Been thanked: 0 time

Re: How To Make a Custom UIView: A 5 Star Rating View

Postby rwenderlich » Mon Jan 10, 2011 9:20 pm

You could but that isn't the same effect I wanted (I wanted it to look similar to how you rate apps in the App Store).
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
User avatar
rwenderlich
Team Member
Site Admin
 
Posts: 2155
Joined: Thu Dec 23, 2010 4:14 pm
Has thanked: 28 times
Been thanked: 338 times

Rating View in a custom table cell

Postby achoura » Tue Jan 11, 2011 9:46 am

Good Morning ;)

I was trying to insert the RateView inside a Custom Cell to show a list of rated hotels.

i've created a class derived from UITableViewCell and added 2 UILabels, UIImageView and "RateView"

the liaison is correct if Interface builder, the property synthesized . but didn't find how to set the rate value, the stars images ,,, :( :(

this is inside my cellForRowatindexPath :
Code: Select all
   // Configure the cell.
   [[cell nomHotel] setText:@"Mouradi"];
   [[cell villeHotel] setText:@"Hammamat"];
   
   RateView *cellRateView = [[RateView alloc] init];
   cellRateView.notSelectedImage = [UIImage imageNamed:@"emptyStar.png"];
   cellRateView.halfSelectedImage = [UIImage imageNamed:@"emptyStar.png"];
   cellRateView.fullSelectedImage = [UIImage imageNamed:@"fullStar.png"];
   cellRateView.rating = 2;
   cellRateView.editable = NO;
   
   cell.ratingHotel = cellRateView;

    return cell;


it's wrong,, but doing [[cell ratingHotel] setRating:3]; doesn't work either :!: :!: :!:


HELPPPP :?
achoura
n00b
 
Posts: 3
Joined: Tue Jan 11, 2011 9:38 am
Has thanked: 0 time
Been thanked: 0 time

Re: How To Make a Custom UIView: A 5 Star Rating View

Postby rwenderlich » Thu Jan 13, 2011 6:22 pm

At a quick glance, looks like you forgot to set the maxRating. Try this:

Code: Select all
cellRateView.maxRating = 5;
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
User avatar
rwenderlich
Team Member
Site Admin
 
Posts: 2155
Joined: Thu Dec 23, 2010 4:14 pm
Has thanked: 28 times
Been thanked: 338 times

Re: How To Make a Custom UIView: A 5 Star Rating View

Postby abhijit » Tue Jan 25, 2011 11:57 am

Very helpful tutorial
I regularly see your blog and be in touch with the updates as well as all posts .. all the tutorials are helpful and can be understood by a newbie also.
abhijit
n00b
 
Posts: 1
Joined: Tue Jan 25, 2011 11:53 am
Has thanked: 0 time
Been thanked: 0 time

Next

Return to Official Tutorials

Who is online

Users browsing this forum: No registered users and 9 guests