Açıklama Yok

CollectTableCell.m 6.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. //
  2. // TAPindanCell.m
  3. // FirstLink
  4. //
  5. // Created by Lemon on 15/4/25.
  6. // Copyright (c) 2015年 FirstLink. All rights reserved.
  7. //
  8. #import "CollectTableCell.h"
  9. @interface CollectTableCell ()
  10. @property (nonatomic, strong) UIView *bgView;
  11. @property (nonatomic, strong) UILabel *estimateTitleLabel;
  12. @end
  13. @implementation CollectTableCell
  14. - (void)awakeFromNib {
  15. // Initialization code
  16. [super awakeFromNib];
  17. }
  18. - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
  19. [super setSelected:selected animated:animated];
  20. // Configure the view for the selected state
  21. }
  22. - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  23. self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
  24. if (self) {
  25. self.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
  26. self.backgroundColor = RGBACOLOR(235, 235, 241, 1);
  27. [self layoutAllCompoments];
  28. }
  29. return self;
  30. }
  31. #pragma mark - Properties
  32. - (UIView *)bgView {
  33. if (!_bgView) {
  34. _bgView = [[UIView alloc] init];
  35. _bgView.backgroundColor = [UIColor whiteColor];
  36. }
  37. return _bgView;
  38. }
  39. - (UIImageView *)photoImageView {
  40. if (!_photoImageView) {
  41. _photoImageView = [[UIImageView alloc] init];
  42. }
  43. return _photoImageView;
  44. }
  45. - (TTTAttributedLabel *)descLabel {
  46. if (!_descLabel) {
  47. _descLabel = [[TTTAttributedLabel alloc] init];
  48. _descLabel.font = [UIFont systemFontOfSize:14.0];
  49. _descLabel.verticalAlignment = TTTAttributedLabelVerticalAlignmentTop;
  50. _descLabel.numberOfLines = 0;
  51. _descLabel.leading = 4;
  52. _descLabel.textColor = UIColorFromRGB(0x333333);
  53. }
  54. return _descLabel;
  55. }
  56. - (UILabel *)estimatePriceLabel {
  57. if (!_estimatePriceLabel) {
  58. _estimatePriceLabel = [[UILabel alloc] init];
  59. _estimatePriceLabel.font = [UIFont systemFontOfSize:14.0];
  60. _estimatePriceLabel.textColor = UIColorFromRGB(0x00c8a9);
  61. _estimatePriceLabel.adjustsFontSizeToFitWidth = YES;
  62. }
  63. return _estimatePriceLabel;
  64. }
  65. #pragma mark - Edit
  66. - (UIView *)overlayerView {
  67. if (!_overlayerView)
  68. {
  69. _overlayerView = [[UIView alloc] init];
  70. _overlayerView.backgroundColor = [UIColor clearColor];
  71. UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self
  72. action:@selector(didClickView:)];
  73. [_overlayerView addGestureRecognizer:tapGesture];
  74. _overlayerView.userInteractionEnabled = YES;
  75. [_overlayerView addSubview:self.selectStatusIcon];
  76. self.selectStatusIcon.translatesAutoresizingMaskIntoConstraints = NO;
  77. [_overlayerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"[_selectStatusIcon(24)]-10-|"
  78. options:0
  79. metrics:nil
  80. views:NSDictionaryOfVariableBindings(_selectStatusIcon)]];
  81. [_overlayerView addConstraint:[NSLayoutConstraint constraintWithItem:self.selectStatusIcon attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeHeight multiplier:1.0 constant:24.0]];
  82. [_overlayerView addConstraint:[NSLayoutConstraint constraintWithItem:self.selectStatusIcon attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:_overlayerView attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0.0]];
  83. }
  84. return _overlayerView;
  85. }
  86. - (IBAction)didClickView:(id)sender {
  87. [self setCardSelected:!self.isSelected];
  88. }
  89. - (UIImageView *)selectStatusIcon {
  90. if (!_selectStatusIcon) {
  91. _selectStatusIcon = [[UIImageView alloc] init];
  92. _selectStatusIcon.image = [UIImage imageNamed:@"Alpha3_UnselectedIcon"];
  93. }
  94. return _selectStatusIcon;
  95. }
  96. - (void)setCardSelected:(BOOL)selected {
  97. _isSelected = selected;
  98. self.selectStatusIcon.image = selected ? [UIImage imageNamed:@"Alpha3_SelectedIcon"] : [UIImage imageNamed:@"Alpha3_UnselectedIcon"];
  99. if (self.clickCallback) {
  100. self.clickCallback(self, (int)self.tag, self.isSelected);
  101. }
  102. }
  103. - (void)setCellEditStatus:(BOOL)isEditing {
  104. if (isEditing) {
  105. self.overlayerView.hidden = NO;
  106. } else {
  107. self.overlayerView.hidden = YES;
  108. }
  109. }
  110. #pragma mark - Layout
  111. - (void)layoutAllCompoments {
  112. WeakSelf(weakSelf);
  113. [self.contentView addSubview:self.bgView];
  114. [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  115. make.left.equalTo(weakSelf.contentView);
  116. make.right.equalTo(weakSelf.contentView);
  117. make.top.equalTo(weakSelf.contentView).with.offset(10);
  118. make.bottom.equalTo(weakSelf.contentView).with.offset(0);
  119. }];
  120. [self.bgView addSubview:self.photoImageView];
  121. [self.photoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  122. make.left.equalTo(weakSelf.bgView).with.offset(10);
  123. make.centerY.equalTo(weakSelf.bgView);
  124. make.size.mas_equalTo(CGSizeMake(102, 102));
  125. }];
  126. [self.bgView addSubview:self.descLabel];
  127. [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  128. make.left.equalTo(weakSelf.photoImageView.mas_right).with.offset(10);
  129. make.right.equalTo(weakSelf.bgView).with.offset(-18);
  130. make.top.equalTo(weakSelf.bgView).with.offset(18);
  131. make.height.mas_equalTo(60);
  132. }];
  133. [self.bgView addSubview:self.estimatePriceLabel];
  134. [self.estimatePriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  135. make.left.equalTo(weakSelf.photoImageView.mas_right).with.offset(10);
  136. make.right.equalTo(weakSelf.bgView).with.offset(-10);
  137. make.bottom.equalTo(weakSelf.bgView).with.offset(-18);
  138. make.height.mas_equalTo(18);
  139. }];
  140. [self layoutIfCellForEditable];
  141. }
  142. - (void)layoutIfCellForEditable {
  143. WeakSelf(weakSelf);
  144. self.overlayerView.hidden = YES;
  145. [self.bgView addSubview:self.overlayerView];
  146. [self.overlayerView mas_makeConstraints:^(MASConstraintMaker *make) {
  147. make.left.equalTo(weakSelf.contentView);
  148. make.right.equalTo(weakSelf.contentView);
  149. make.top.equalTo(weakSelf.contentView);
  150. make.bottom.equalTo(weakSelf.contentView);
  151. }];
  152. }
  153. #pragma mark - Helper
  154. - (void)setAttributedEstimatePrice:(NSString *)price {
  155. if (!price || price.length == 0) {
  156. self.estimatePriceLabel.text = @"";
  157. return;
  158. }
  159. self.estimatePriceLabel.text = [NSString stringWithFormat:@"¥ %@", price];
  160. }
  161. + (CGFloat)height {
  162. return 118 + 10;
  163. }
  164. @end