-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDetailAnswerCell.m
68 lines (55 loc) · 2.01 KB
/
DetailAnswerCell.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// DetailAnswerCell.m
// unnamed
//
// Created by Bruce Ng on 2/19/15.
// Copyright (c) 2015 com.yahoo. All rights reserved.
//
#import "DetailAnswerCell.h"
#import "GRKBarGraphView.h"
#import "UIColor+AppColor.h"
@interface DetailAnswerCell()
@property (nonatomic, strong) Answer *answer;
@property (nonatomic, assign) NSInteger totalVotes;
@property (weak, nonatomic) IBOutlet UILabel *answerIndexLabel;
@property (weak, nonatomic) IBOutlet UILabel *answerLabel;
@property (weak, nonatomic) IBOutlet GRKBarGraphView *barGraph;
@property (weak, nonatomic) IBOutlet UILabel *percentLabel;
@end
@implementation DetailAnswerCell
- (void)awakeFromNib {
// Initialization code
self.barGraph.barStyle = GRKBarStyleFromRight;
self.barGraph.barColor = [UIColor appTintColor];
self.barGraph.tintColor = [UIColor appTintColor];
self.barGraph.contentMode = UIViewContentModeCenter;
self.barGraph.animationDuration = 1;
[self.selectionImage setImage:[UIImage imageNamed:@"answer_unselected"]];
}
- (void)layoutSubviews {
self.answerIndexLabel.text = [NSString stringWithFormat:@"%ld.", (long)self.answer.index +1];
self.answerLabel.text = self.answer.text;
float percent = self.totalVotes > 0 ? (float)self.answer.count / (float)self.totalVotes : 0;
self.percentLabel.text = [NSString stringWithFormat:@"%.1f%%", percent * 100];
self.barGraph.percent = percent;
}
- (void) initWithAnswer:(Answer *)answer totalVotes:(NSInteger)count {
_answer = answer;
_totalVotes = count;
}
- (void)setIsCurrentVote:(BOOL)isCurrentVote {
_isCurrentVote = isCurrentVote;
[self displayVoteIcon];
}
- (void) displayVoteIcon {
if (self.isCurrentVote) {
[self.selectionImage setImage:[UIImage imageNamed:@"answer_selected"]];
} else {
[self.selectionImage setImage:[UIImage imageNamed:@"answer_unselected"]];
}
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
[super setSelected:selected animated:animated];
// Configure the view for the selected state
}
@end