ChatSectionHeaderView.m 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. // _____ _
  2. // |_ _| |_ _ _ ___ ___ _ __ __ _
  3. // | | | ' \| '_/ -_) -_) ' \/ _` |_
  4. // |_| |_||_|_| \___\___|_|_|_\__,_(_)
  5. //
  6. // Threema iOS Client
  7. // Copyright (c) 2015-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 "ChatSectionHeaderView.h"
  21. #import "Threema-Swift.h"
  22. @interface ChatSectionHeaderView ()
  23. @property UILabel *dateLabel;
  24. @end
  25. @implementation ChatSectionHeaderView
  26. - (instancetype)initWithFrame:(CGRect)frame
  27. {
  28. self = [super initWithFrame:frame];
  29. if (self) {
  30. [self setup];
  31. }
  32. return self;
  33. }
  34. - (void)setup {
  35. self.userInteractionEnabled = NO;
  36. self.backgroundColor = [UIColor clearColor];
  37. }
  38. - (void)makeRoundRectLabel {
  39. CGRect labelFrame = CGRectMake(0.0, 8.0, self.frame.size.width, _fontSize + 6.0);
  40. _dateLabel = [[RoundedRectLabel alloc] initWithFrame:labelFrame];
  41. _dateLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth;
  42. _dateLabel.clearsContextBeforeDrawing = NO;
  43. _dateLabel.font = [UIFont boldSystemFontOfSize:_fontSize];
  44. _dateLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  45. _dateLabel.textAlignment = NSTextAlignmentCenter;
  46. _dateLabel.contentMode = UIViewContentModeCenter;
  47. _dateLabel.alpha = 0.8;
  48. _dateLabel.backgroundColor = [Colors backgroundDark];
  49. _dateLabel.textColor = [Colors fontLight];
  50. [self addSubview:_dateLabel];
  51. _dateLabel.text = _text;
  52. }
  53. - (void)setText:(NSString *)text {
  54. _text = text;
  55. _dateLabel.text = text;
  56. }
  57. - (void)setFontSize:(CGFloat)fontSize {
  58. _fontSize = fontSize;
  59. [self makeRoundRectLabel];
  60. }
  61. - (void)setHidden:(BOOL)hidden {
  62. _dateLabel.hidden = hidden;
  63. }
  64. - (void)setAlpha:(CGFloat)alpha {
  65. _dateLabel.alpha = alpha;
  66. }
  67. - (CGFloat)alpha {
  68. return _dateLabel.alpha;
  69. }
  70. @end