BallotVoteTableCell.m 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  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. #define MAX_NUMBER_OF_LINES 3
  21. #define LABEL_HEIGHT_PADDING 23.0
  22. #import "BallotVoteTableCell.h"
  23. #import "RectUtil.h"
  24. @implementation BallotVoteTableCell
  25. - (void)awakeFromNib {
  26. [super awakeFromNib];
  27. UIImage *tmpImage = _checkmarkView.image;
  28. _checkmarkView.image = [tmpImage imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate];
  29. self.tintColor = [Colors main];
  30. _choiceLabel.maxLines = MAX_NUMBER_OF_LINES;
  31. _choiceLabel.paddingHeight = LABEL_HEIGHT_PADDING;
  32. }
  33. - (void)setFrame:(CGRect)frame {
  34. CGRect currentFrame = self.frame;
  35. [super setFrame:frame];
  36. if (CGRectGetHeight(frame) != CGRectGetHeight(currentFrame)) {
  37. _choiceLabel.frame = [RectUtil rect:_choiceLabel.frame centerVerticalIn:frame round:YES];
  38. _checkmarkView.frame = [RectUtil rect:_checkmarkView.frame centerVerticalIn:frame];
  39. _voteCountLabel.frame = [RectUtil rect:_voteCountLabel.frame centerVerticalIn:frame];
  40. }
  41. }
  42. + (CGFloat)calculateHeightFor:(NSString *)text inFrame:(CGRect)rect {
  43. ResizingLabel *label = [[ResizingLabel alloc] initWithFrame:rect];
  44. label.maxLines = MAX_NUMBER_OF_LINES;
  45. label.paddingHeight = LABEL_HEIGHT_PADDING;
  46. label.text = text;
  47. [label sizeToFit];
  48. return CGRectGetHeight(label.frame);
  49. }
  50. @end