Nenhuma Descrição

FKCircleDescCell.m 3.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. //
  2. // FKCircleDescCell.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/6/12.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKCircleDescCell.h"
  9. #import "FKCircleBestViewModel.h"
  10. @interface FKCircleDescCell ()
  11. @property (nonatomic, strong) UIView *containerView;
  12. @property (nonatomic, strong) UIView *cornerCoverView;
  13. @end
  14. @implementation FKCircleDescCell
  15. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
  16. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
  17. [self addAllSubviews];
  18. self.selectionStyle = UITableViewCellSelectionStyleNone;
  19. self.backgroundColor = [UIColor clearColor];
  20. }
  21. return self;
  22. }
  23. - (void)addAllSubviews{
  24. [self.contentView addSubview:self.containerView];
  25. [self.contentView addSubview:self.cornerCoverView];
  26. [self.containerView addSubview:self.titleLabel];
  27. [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
  28. make.edges.insets(UIEdgeInsetsMake(0, 5, 0, 5));
  29. }];
  30. [self.cornerCoverView mas_makeConstraints:^(MASConstraintMaker *make) {
  31. make.left.right.top.equalTo(self.containerView);
  32. make.height.mas_equalTo(8);
  33. }];
  34. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.top.equalTo(self.containerView).offset(11);
  36. make.left.equalTo(self.containerView).offset(12);
  37. make.right.equalTo(self.containerView).offset(- 12);
  38. }];
  39. }
  40. - (void)fk_configWithViewModel:(id)viewModel indexPath:(NSIndexPath *)indexPath{
  41. if ([viewModel isKindOfClass:[FKCircleBestViewModel class]]) {
  42. FKCircleBestViewModel *bestViewModel = (FKCircleBestViewModel *)viewModel;
  43. FKCircleContentItem *contentItem = [bestViewModel circleContentItemForIndexPath:indexPath];
  44. self.titleLabel.text = contentItem.shareItem.desc;
  45. NSInteger rowCount = [bestViewModel numberOfRowsInSection:indexPath.section];
  46. [self setLastLine:indexPath.row == rowCount - 1];
  47. }
  48. }
  49. + (CGFloat)cellHeightForTitle:(NSString *)title{
  50. if (title.length == 0) return 15;
  51. CGFloat textH = [FLStringHelper sizeOfAttributeString:title
  52. font:[UIFont systemFontOfSize:14]
  53. width:UISCREENWIDTH - 34 maxRow:2].height;
  54. return textH + 25;
  55. }
  56. - (void)setLastLine:(BOOL)lastLine{
  57. // 最后一行圆角
  58. self.containerView.layer.cornerRadius = 0.0f;
  59. self.cornerCoverView.hidden = YES;
  60. if (lastLine){
  61. self.containerView.layer.cornerRadius = 4.0f;
  62. self.cornerCoverView.hidden = NO;
  63. }
  64. }
  65. - (UIView *)containerView{
  66. if (_containerView == nil) {
  67. _containerView = [[UIView alloc]init];
  68. _containerView.backgroundColor = [UIColor whiteColor];
  69. }
  70. return _containerView;
  71. }
  72. - (UIView *)cornerCoverView{
  73. if (_cornerCoverView == nil) {
  74. _cornerCoverView = [[UIView alloc]init];
  75. _cornerCoverView.backgroundColor = [UIColor whiteColor];
  76. }
  77. return _cornerCoverView;
  78. }
  79. - (UILabel *)titleLabel{
  80. if (_titleLabel == nil) {
  81. _titleLabel = [[UILabel alloc]init];
  82. _titleLabel.textColor = UIColorFromRGB(0x000000);
  83. _titleLabel.font = [UIFont systemFontOfSize:14];
  84. _titleLabel.numberOfLines = 2;
  85. _titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  86. }
  87. return _titleLabel;
  88. }
  89. @end