You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1.8 KiB

5 years ago
5 years ago
  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. @implementation FLEXMultilineTableViewCell
  10. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  11. {
  12. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  13. if (self) {
  14. self.textLabel.numberOfLines = 0;
  15. self.detailTextLabel.numberOfLines = 0;
  16. }
  17. return self;
  18. }
  19. - (void)layoutSubviews
  20. {
  21. [super layoutSubviews];
  22. self.textLabel.frame = UIEdgeInsetsInsetRect(self.contentView.bounds, [[self class] labelInsets]);
  23. }
  24. + (UIEdgeInsets)labelInsets
  25. {
  26. return UIEdgeInsetsMake(10.0, 15.0, 10.0, 15.0);
  27. }
  28. + (CGFloat)preferredHeightWithAttributedText:(NSAttributedString *)attributedText inTableViewWidth:(CGFloat)tableViewWidth style:(UITableViewStyle)style showsAccessory:(BOOL)showsAccessory
  29. {
  30. CGFloat labelWidth = tableViewWidth;
  31. // Content view inset due to accessory view observed on iOS 8.1 iPhone 6.
  32. if (showsAccessory) {
  33. labelWidth -= 34.0;
  34. }
  35. UIEdgeInsets labelInsets = [self labelInsets];
  36. labelWidth -= (labelInsets.left + labelInsets.right);
  37. CGSize constrainSize = CGSizeMake(labelWidth, CGFLOAT_MAX);
  38. CGFloat preferredLabelHeight = ceil([attributedText boundingRectWithSize:constrainSize options:NSStringDrawingUsesLineFragmentOrigin context:nil].size.height);
  39. CGFloat preferredCellHeight = preferredLabelHeight + labelInsets.top + labelInsets.bottom + 1.0;
  40. return preferredCellHeight;
  41. }
  42. @end
  43. @implementation FLEXMultilineDetailTableViewCell
  44. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
  45. {
  46. return [super initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:reuseIdentifier];
  47. }
  48. @end