19 #pragma mark Initialization 21 - (id)initWithDefault:(UIImage*)star highlighted:(UIImage*)highlightedStar position:(
int)index allowFractions:(BOOL)fractions {
22 self = [
super initWithFrame:CGRectZero];
30 self.frame = CGRectMake((star.size.width*index), 0, star.size.width, star.size.height+
kEdgeInsetBottom);
32 [
self setImageEdgeInsets:UIEdgeInsetsMake(0, 0, kEdgeInsetBottom, 0)];
33 [
self setBackgroundColor:[UIColor clearColor]];
35 [
self setAccessibilityLabel:@"1 star"];
37 [
self setAccessibilityLabel:[NSString stringWithFormat:@"%d stars", index+1]];
44 - (UIImage *)croppedImage:(UIImage*)image {
47 float xOffset = partWidth*part;
48 CGRect newFrame = CGRectMake(xOffset, 0, partWidth , image.size.height * image.scale);
49 CGImageRef resultImage = CGImageCreateWithImageInRect([image CGImage], newFrame);
50 UIImage *result = [UIImage imageWithCGImage:resultImage scale:image.scale orientation:image.imageOrientation];
51 CGImageRelease(resultImage);
58 #pragma mark UIView methods 60 - (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
61 return self.superview;
65 #pragma mark Layouting 67 - (void)centerIn:(CGRect)_frame with:(
int)numberOfStars {
68 CGSize size =
self.frame.size;
70 float height =
self.frame.size.height;
71 float frameHeight = _frame.size.height;
72 float newY = (frameHeight-height)/2;
74 float widthOfStars =
self.frame.size.width * numberOfStars;
75 float frameWidth = _frame.size.width;
76 float gapToApply = (frameWidth-widthOfStars)/2;
78 self.frame = CGRectMake((size.width*
self.tag) + gapToApply, newY, size.width, size.height);
81 - (void)setStarImage:(UIImage*)starImage highlightedStarImage:(UIImage*)highlightedImage {
82 [
self setImage:starImage forState:UIControlStateNormal];
83 [
self setImage:highlightedImage forState:UIControlStateSelected];
84 [
self setImage:highlightedImage forState:UIControlStateHighlighted];
void setStarImage:highlightedStarImage:(UIImage *starImage, [highlightedStarImage] UIImage *highlightedImage)
#define kNumberOfFractions
UIImage * croppedImage:(UIImage *image)