Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Rearrange code

  • Loading branch information...
commit 0c775887a8aa3eda449ee95b52effc5ec2ba8c07 1 parent fac44e1
Edward Chiang authored
Showing with 35 additions and 35 deletions.
  1. +35 −35 RateStars/RSTapRateView.m
View
70 RateStars/RSTapRateView.m
@@ -35,16 +35,16 @@ - (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
// Initialization code
-
+
_rating = 0;
-
+
_textLabel = [[UILabel alloc] init];
_textLabel.text = kTextLabelText;
_textLabel.font = [UIFont boldSystemFontOfSize:10.f];
_textLabel.textColor = [UIColor grayColor];
_textLabel.backgroundColor = [UIColor clearColor];
[self addSubview:_textLabel];
-
+
_oneStarButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_oneStarButton setImage:[UIImage imageNamed:@"star_empty.png"] forState:UIControlStateNormal];
[_oneStarButton setImage:[UIImage imageNamed:@"star_full.png"] forState:UIControlStateSelected];
@@ -52,11 +52,11 @@ - (id)initWithFrame:(CGRect)frame {
_oneStarButton.tag = 1;
[self.oneStarButton sizeToFit];
[self addSubview:_oneStarButton];
-
+
_oneStarReflectionView = [[UIImageView alloc] init];
_oneStarReflectionView.alpha = kDefaultReflectionOpacity;
[self addSubview:_oneStarReflectionView];
-
+
_twoStarButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_twoStarButton setImage:[UIImage imageNamed:@"star_empty.png"] forState:UIControlStateNormal];
[_twoStarButton setImage:[UIImage imageNamed:@"star_full.png"] forState:UIControlStateSelected];
@@ -64,11 +64,11 @@ - (id)initWithFrame:(CGRect)frame {
_twoStarButton.tag = 2;
[self.twoStarButton sizeToFit];
[self addSubview:_twoStarButton];
-
+
_twoStarReflectionView = [[UIImageView alloc] init];
_twoStarReflectionView.alpha = kDefaultReflectionOpacity;
[self addSubview:_twoStarReflectionView];
-
+
_threeStarButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_threeStarButton setImage:[UIImage imageNamed:@"star_empty.png"] forState:UIControlStateNormal];
[_threeStarButton setImage:[UIImage imageNamed:@"star_full.png"] forState:UIControlStateSelected];
@@ -76,11 +76,11 @@ - (id)initWithFrame:(CGRect)frame {
_threeStarButton.tag = 3;
[self.threeStarButton sizeToFit];
[self addSubview:_threeStarButton];
-
+
_threeStarReflectionView = [[UIImageView alloc] init];
_threeStarReflectionView.alpha = kDefaultReflectionOpacity;
[self addSubview:_threeStarReflectionView];
-
+
_fourStarButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_fourStarButton setImage:[UIImage imageNamed:@"star_empty.png"] forState:UIControlStateNormal];
[_fourStarButton setImage:[UIImage imageNamed:@"star_full.png"] forState:UIControlStateSelected];
@@ -92,7 +92,7 @@ - (id)initWithFrame:(CGRect)frame {
_fourStarReflectionView = [[UIImageView alloc] init];
_fourStarReflectionView.alpha = kDefaultReflectionOpacity;
[self addSubview:_fourStarReflectionView];
-
+
_fiveStarButton = [UIButton buttonWithType:UIButtonTypeCustom];
[_fiveStarButton setImage:[UIImage imageNamed:@"star_empty.png"] forState:UIControlStateNormal];
[_fiveStarButton setImage:[UIImage imageNamed:@"star_full.png"] forState:UIControlStateSelected];
@@ -100,13 +100,13 @@ - (id)initWithFrame:(CGRect)frame {
_fiveStarButton.tag = 5;
[_fiveStarButton sizeToFit];
[self addSubview:_fiveStarButton];
-
+
_fiveStarReflectionView = [[UIImageView alloc] init];
_fiveStarReflectionView.alpha = kDefaultReflectionOpacity;
[self addSubview:_fiveStarReflectionView];
-
+
self.backgroundColor = [UIColor colorWithHue:0.611 saturation:0.026 brightness:0.922 alpha:1.];
-
+
}
return self;
}
@@ -124,7 +124,7 @@ - (void)dealloc {
- (void)layoutSubviews {
[super layoutSubviews];
[_textLabel sizeToFit];
-
+
CGFloat starButtonWidth = 24.f;
CGFloat starButtonHeight = 24.f;
CGFloat starButtonSpacing = 20.f;
@@ -133,34 +133,34 @@ - (void)layoutSubviews {
// One
self.oneStarButton.frame = CGRectMake(centerButtonLeft - (starButtonSpacing + starButtonWidth) * 2, centerButtonTop, starButtonWidth, starButtonHeight);
-
+
_oneStarReflectionView.image = [UIImageView reflectedImage:_oneStarButton.imageView withHeight:_oneStarButton.imageView.bounds.size.height * kDefaultReflectionFraction];
_oneStarReflectionView.frame = CGRectMake(centerButtonLeft - (starButtonSpacing + starButtonWidth) * 2, centerButtonTop + starButtonHeight + 1.f, starButtonWidth, starButtonHeight);
-
+
// Two
self.twoStarButton.frame = CGRectMake(centerButtonLeft - (starButtonSpacing + starButtonWidth) * 1, centerButtonTop, starButtonWidth, starButtonHeight);
-
+
_twoStarReflectionView.image = [UIImageView reflectedImage:_twoStarButton.imageView withHeight:_twoStarButton.imageView.bounds.size.height * kDefaultReflectionFraction];
_twoStarReflectionView.frame = CGRectMake(self.twoStarButton.frame.origin.x, centerButtonTop + starButtonHeight + 1.f, starButtonWidth, starButtonHeight);
-
+
// Three
self.threeStarButton.frame = CGRectMake(centerButtonLeft, centerButtonTop, starButtonWidth, starButtonHeight);
-
+
_threeStarReflectionView.image = [UIImageView reflectedImage:_threeStarButton.imageView withHeight:_threeStarButton.imageView.bounds.size.height * kDefaultReflectionFraction];
_threeStarReflectionView.frame = CGRectMake(centerButtonLeft, centerButtonTop + starButtonHeight + 1.f, starButtonWidth, starButtonHeight);
-
+
// Four
self.fourStarButton.frame = CGRectMake(centerButtonLeft + (starButtonSpacing + starButtonWidth) * 1, centerButtonTop, starButtonWidth, starButtonHeight);
-
+
_fourStarReflectionView.image = [UIImageView reflectedImage:_fourStarButton.imageView withHeight:_fourStarButton.imageView.bounds.size.height * kDefaultReflectionFraction];
_fourStarReflectionView.frame = CGRectMake(centerButtonLeft + (starButtonSpacing + starButtonWidth) * 1, centerButtonTop + starButtonHeight + 1.f, starButtonWidth, starButtonHeight);
-
+
// Five
self.fiveStarButton.frame = CGRectMake(centerButtonLeft + (starButtonSpacing + starButtonWidth) * 2, centerButtonTop, starButtonWidth, starButtonHeight);
-
+
_fiveStarReflectionView.image = [UIImageView reflectedImage:_fiveStarButton.imageView withHeight:_fiveStarButton.imageView.bounds.size.height * kDefaultReflectionFraction];
_fiveStarReflectionView.frame = CGRectMake(centerButtonLeft + (starButtonSpacing + starButtonWidth) * 2, centerButtonTop + starButtonHeight + 1.f, starButtonWidth, starButtonHeight);
-
+
self.textLabel.frame = CGRectMake((self.bounds.size.width - self.textLabel.bounds.size.width) / 2, self.bounds.size.height - self.textLabel.bounds.size.height - 1.f, self.textLabel.bounds.size.width, self.textLabel.bounds.size.height);
}
@@ -185,25 +185,25 @@ - (void)tapStarButton:(id)object {
if ([object isKindOfClass:[UIButton class]]) {
UIButton *currentButton = (UIButton *)object;
currentButton.selected = YES;
-
+
self.textLabel.text = nil;
-
+
self.rating = currentButton.tag;
-
+
[self reflectionViewRefresh];
-
+
[self.delegate tapDidRateView:self rating:self.rating];
}
}
- (void)setRating:(NSInteger)aRating {
- self.oneStarButton.selected = aRating >= self.oneStarButton.tag;
- self.twoStarButton.selected = aRating >= self.twoStarButton.tag;
- self.threeStarButton.selected = aRating>= self.threeStarButton.tag;
- self.fourStarButton.selected = aRating >= self.fourStarButton.tag;
- self.fiveStarButton.selected = aRating >= self.fiveStarButton.tag;
-
- _rating = aRating;
+ self.oneStarButton.selected = aRating >= self.oneStarButton.tag;
+ self.twoStarButton.selected = aRating >= self.twoStarButton.tag;
+ self.threeStarButton.selected = aRating>= self.threeStarButton.tag;
+ self.fourStarButton.selected = aRating >= self.fourStarButton.tag;
+ self.fiveStarButton.selected = aRating >= self.fiveStarButton.tag;
+
+ _rating = aRating;
}
- (void)reflectionViewRefresh {
Please sign in to comment.
Something went wrong with that request. Please try again.