BallotResultMatrixCell.m 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2014-2020 Threema GmbH
  8. //
  9. // This program is free software: you can redistribute it and/or modify
  10. // it under the terms of the GNU Affero General Public License, version 3,
  11. // as published by the Free Software Foundation.
  12. //
  13. // This program is distributed in the hope that it will be useful,
  14. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. // GNU Affero General Public License for more details.
  17. //
  18. // You should have received a copy of the GNU Affero General Public License
  19. // along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. #import "BallotResultMatrixCell.h"
  21. #import "UIImage+ColoredImage.h"
  22. #import "BallotResult.h"
  23. #import "RectUtil.h"
  24. #import "UIImage+ColoredImage.h"
  25. #define CHECKMARK_IMAGE @"Checkmark"
  26. #define CHECKMARK_SCALE 0.4
  27. #define MINUS_IMAGE @"Minus"
  28. #define MINUS_VERTICAL_SCALE 0.32
  29. #define MINUS_HORIZONTAL_SCALE 0.06
  30. #define IMAGE_COLOR [Colors fontNormal]
  31. @implementation BallotResultMatrixCell
  32. - (instancetype)initWithFrame:(CGRect)frame
  33. {
  34. self = [super initWithFrame:frame];
  35. if (self) {
  36. self.layer.borderWidth = 1.0;
  37. self.layer.borderColor = [UIColor whiteColor].CGColor;
  38. self.isAccessibilityElement = YES;
  39. }
  40. return self;
  41. }
  42. - (void)setBorderColor: (UIColor *)color {
  43. self.layer.borderColor = color.CGColor;
  44. }
  45. - (void)setBorderWidth: (CGFloat)width {
  46. self.layer.borderWidth = width;
  47. }
  48. - (void)setColorForChoice:(UIColor *)color {
  49. NSArray *subViews = self.subviews;
  50. [subViews enumerateObjectsUsingBlock:^(id _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
  51. if ([obj isKindOfClass:[UIImageView class]]) {
  52. UIImageView *imageView = (UIImageView *)obj;
  53. imageView.image = [imageView.image imageWithTint:color];
  54. }
  55. }];
  56. }
  57. - (void)updateResultForChoice:(BallotChoice *)choice andParticipant:(NSString *)participant {
  58. BallotResult *result = [choice getResultForId: participant];
  59. if (result == nil) {
  60. ;//
  61. } else if (result.boolValue) {
  62. UIImageView *checkmark = [self getCheckmark];
  63. [self addSubview: checkmark];
  64. self.accessibilityValue = NSLocalizedString(@"yes", nil);
  65. } else {
  66. UIImageView *minus = [self getMinus];
  67. [self addSubview: minus];
  68. self.accessibilityValue = NSLocalizedString(@"no", nil);
  69. }
  70. }
  71. - (UIImageView *)getCheckmark {
  72. return [self getImage:CHECKMARK_IMAGE verticalScale:CHECKMARK_SCALE horizontalScale:CHECKMARK_SCALE];
  73. }
  74. - (UIImageView *)getMinus {
  75. return [self getImage:MINUS_IMAGE verticalScale:MINUS_VERTICAL_SCALE horizontalScale:MINUS_HORIZONTAL_SCALE];
  76. }
  77. - (UIImageView *)getImage:(NSString *)imageName verticalScale:(CGFloat)verticalScale horizontalScale:(CGFloat)horizontalScale {
  78. CGRect rect = CGRectMake(0.0, 0.0, self.bounds.size.width*verticalScale, self.bounds.size.height*horizontalScale);
  79. rect = [RectUtil rect:rect centerIn:self.bounds];
  80. UIImageView *imageView = [[UIImageView alloc] initWithFrame: rect];
  81. UIImage *image;
  82. UIImage *tmpImage = [UIImage imageNamed:imageName];
  83. image = [tmpImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
  84. self.tintColor = IMAGE_COLOR;
  85. [imageView setImage:image];
  86. return imageView;
  87. }
  88. @end