MessageSeparatorTableViewCell.m 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /**
  2. * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
  3. * SPDX-License-Identifier: GPL-3.0-or-later
  4. */
  5. #import "MessageSeparatorTableViewCell.h"
  6. @implementation MessageSeparatorTableViewCell
  7. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  8. {
  9. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  10. if (self) {
  11. self.selectionStyle = UITableViewCellSelectionStyleNone;
  12. self.backgroundColor = [UIColor secondarySystemBackgroundColor];
  13. [self configureSubviews];
  14. }
  15. return self;
  16. }
  17. - (void)configureSubviews
  18. {
  19. [self.contentView addSubview:self.separatorLabel];
  20. NSDictionary *views = @{@"separatorLabel": self.separatorLabel};
  21. NSDictionary *metrics = @{@"left": @10,
  22. @"top": @5
  23. };
  24. [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-left-[separatorLabel(>=0)]-left-|" options:0 metrics:metrics views:views]];
  25. [self.contentView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-top-[separatorLabel(14)]-top-|" options:0 metrics:metrics views:views]];
  26. }
  27. - (void)prepareForReuse
  28. {
  29. [super prepareForReuse];
  30. self.separatorLabel.text = @"";
  31. self.selectionStyle = UITableViewCellSelectionStyleNone;
  32. }
  33. #pragma mark - Getters
  34. - (UILabel *)separatorLabel
  35. {
  36. if (!_separatorLabel) {
  37. _separatorLabel = [UILabel new];
  38. _separatorLabel.textAlignment = NSTextAlignmentCenter;
  39. _separatorLabel.translatesAutoresizingMaskIntoConstraints = NO;
  40. _separatorLabel.backgroundColor = [UIColor clearColor];
  41. _separatorLabel.userInteractionEnabled = NO;
  42. _separatorLabel.numberOfLines = 1;
  43. _separatorLabel.font = [UIFont systemFontOfSize:12.0];
  44. _separatorLabel.text = NSLocalizedString(@"Unread messages", nil);
  45. _separatorLabel.textColor = [UIColor secondaryLabelColor];
  46. }
  47. return _separatorLabel;
  48. }
  49. @end