FLEXMultilineTableViewCell.m 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. //
  2. // FLEXMultilineTableViewCell.m
  3. // FLEX
  4. //
  5. // Created by Ryan Olson on 2/13/15.
  6. // Copyright (c) 2020 FLEX Team. All rights reserved.
  7. //
  8. #import "FLEXMultilineTableViewCell.h"
  9. #import "UIView+FLEX_Layout.h"
  10. #import "FLEXUtility.h"
  11. @interface FLEXMultilineTableViewCell ()
  12. @property (nonatomic, readonly) UILabel *_titleLabel;
  13. @property (nonatomic, readonly) UILabel *_subtitleLabel;
  14. @property (nonatomic) BOOL constraintsUpdated;
  15. @end
  16. @implementation FLEXMultilineTableViewCell
  17. - (void)postInit {
  18. [super postInit];
  19. self.titleLabel.numberOfLines = 0;
  20. self.subtitleLabel.numberOfLines = 0;
  21. }
  22. + (UIEdgeInsets)labelInsets {
  23. return UIEdgeInsetsMake(10.0, 16.0, 10.0, 8.0);
  24. }
  25. + (CGFloat)preferredHeightWithAttributedText:(NSAttributedString *)attributedText
  26. maxWidth:(CGFloat)contentViewWidth
  27. style:(UITableViewStyle)style
  28. showsAccessory:(BOOL)showsAccessory {
  29. CGFloat labelWidth = contentViewWidth;
  30. // Content view inset due to accessory view observed on iOS 8.1 iPhone 6.
  31. if (showsAccessory) {
  32. labelWidth -= 34.0;
  33. }
  34. UIEdgeInsets labelInsets = [self labelInsets];
  35. labelWidth -= (labelInsets.left + labelInsets.right);
  36. CGSize constrainSize = CGSizeMake(labelWidth, CGFLOAT_MAX);
  37. CGRect boundingBox = [attributedText
  38. boundingRectWithSize:constrainSize
  39. options:NSStringDrawingUsesLineFragmentOrigin
  40. context:nil
  41. ];
  42. CGFloat preferredLabelHeight = FLEXFloor(boundingBox.size.height);
  43. CGFloat preferredCellHeight = preferredLabelHeight + labelInsets.top + labelInsets.bottom + 1.0;
  44. return preferredCellHeight;
  45. }
  46. @end
  47. @implementation FLEXMultilineDetailTableViewCell
  48. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  49. return [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
  50. }
  51. @end