FLEXMultilineTableViewCell.m 1.8 KB

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