How To Make a Custom UIView in iOS 5: A 5 Star Rating View
33 posts
• Page 1 of 4 • 1, 2, 3, 4
How To Make a Custom UIView in iOS 5: A 5 Star Rating View
This is the official thread to discuss the following blog post: 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
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

rwenderlich - Site Admin
- Posts: 1776
- Joined: Thu Dec 23, 2010 4:14 pm
- Has thanked: 26 times
- Been thanked: 187 times
Re: How To Make a Custom UIView: A 5 Star Rating View
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!
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
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.
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

rwenderlich - Site Admin
- Posts: 1776
- Joined: Thu Dec 23, 2010 4:14 pm
- Has thanked: 26 times
- Been thanked: 187 times
Re: How To Make a Custom UIView: A 5 Star Rating View
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.
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
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

rwenderlich - Site Admin
- Posts: 1776
- Joined: Thu Dec 23, 2010 4:14 pm
- Has thanked: 26 times
- Been thanked: 187 times
Re: How To Make a Custom UIView: A 5 Star Rating View
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
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

rwenderlich - Site Admin
- Posts: 1776
- Joined: Thu Dec 23, 2010 4:14 pm
- Has thanked: 26 times
- Been thanked: 187 times
Rating View in a custom table cell
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 :
it's wrong,, but doing [[cell ratingHotel] setRating:3]; doesn't work either
HELPPPP
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: 1
- 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
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
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
Ray Wenderlich
Blog: http://www.raywenderlich.com
Twitter: http://twitter.com/rwenderlich
- - - - - - - - - - - - - - - - - - - - - - - - - - - -
-

rwenderlich - Site Admin
- Posts: 1776
- Joined: Thu Dec 23, 2010 4:14 pm
- Has thanked: 26 times
- Been thanked: 187 times
Re: How To Make a Custom UIView: A 5 Star Rating View
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.
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
33 posts
• Page 1 of 4 • 1, 2, 3, 4
Who is online
Users browsing this forum: Bing [Bot], Majestic-12 [Bot] and 4 guests