123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- //
- // TAPindanCell.m
- // FirstLink
- //
- // Created by Lemon on 15/4/25.
- // Copyright (c) 2015年 FirstLink. All rights reserved.
- //
- #import "CollectTableCell.h"
- @interface CollectTableCell ()
- @property (nonatomic, strong) UIView *bgView;
- @property (nonatomic, strong) UILabel *estimateTitleLabel;
- @end
- @implementation CollectTableCell
- - (void)awakeFromNib {
- // Initialization code
- [super awakeFromNib];
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
- // Configure the view for the selected state
- }
- - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- self.contentView.autoresizingMask = UIViewAutoresizingFlexibleHeight|UIViewAutoresizingFlexibleWidth;
-
- self.backgroundColor = RGBACOLOR(235, 235, 241, 1);
-
- [self layoutAllCompoments];
- }
- return self;
- }
- #pragma mark - Properties
- - (UIView *)bgView {
- if (!_bgView) {
- _bgView = [[UIView alloc] init];
- _bgView.backgroundColor = [UIColor whiteColor];
- }
- return _bgView;
- }
- - (UIImageView *)photoImageView {
- if (!_photoImageView) {
- _photoImageView = [[UIImageView alloc] init];
- }
- return _photoImageView;
- }
- - (TTTAttributedLabel *)descLabel {
- if (!_descLabel) {
- _descLabel = [[TTTAttributedLabel alloc] init];
- _descLabel.font = [UIFont systemFontOfSize:14.0];
- _descLabel.verticalAlignment = TTTAttributedLabelVerticalAlignmentTop;
- _descLabel.numberOfLines = 0;
- _descLabel.leading = 4;
- _descLabel.textColor = UIColorFromRGB(0x333333);
- }
- return _descLabel;
- }
- - (UILabel *)estimatePriceLabel {
- if (!_estimatePriceLabel) {
- _estimatePriceLabel = [[UILabel alloc] init];
- _estimatePriceLabel.font = [UIFont systemFontOfSize:14.0];
- _estimatePriceLabel.textColor = UIColorFromRGB(0x00c8a9);
- _estimatePriceLabel.adjustsFontSizeToFitWidth = YES;
- }
- return _estimatePriceLabel;
- }
- #pragma mark - Edit
- - (UIView *)overlayerView {
- if (!_overlayerView)
- {
- _overlayerView = [[UIView alloc] init];
- _overlayerView.backgroundColor = [UIColor clearColor];
-
- UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self
- action:@selector(didClickView:)];
- [_overlayerView addGestureRecognizer:tapGesture];
- _overlayerView.userInteractionEnabled = YES;
-
- [_overlayerView addSubview:self.selectStatusIcon];
- self.selectStatusIcon.translatesAutoresizingMaskIntoConstraints = NO;
- [_overlayerView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"[_selectStatusIcon(24)]-10-|"
- options:0
- metrics:nil
- views:NSDictionaryOfVariableBindings(_selectStatusIcon)]];
- [_overlayerView addConstraint:[NSLayoutConstraint constraintWithItem:self.selectStatusIcon attribute:NSLayoutAttributeHeight relatedBy:NSLayoutRelationEqual toItem:nil attribute:NSLayoutAttributeHeight multiplier:1.0 constant:24.0]];
- [_overlayerView addConstraint:[NSLayoutConstraint constraintWithItem:self.selectStatusIcon attribute:NSLayoutAttributeCenterY relatedBy:NSLayoutRelationEqual toItem:_overlayerView attribute:NSLayoutAttributeCenterY multiplier:1.0 constant:0.0]];
- }
-
- return _overlayerView;
- }
- - (IBAction)didClickView:(id)sender {
- [self setCardSelected:!self.isSelected];
- }
- - (UIImageView *)selectStatusIcon {
- if (!_selectStatusIcon) {
- _selectStatusIcon = [[UIImageView alloc] init];
- _selectStatusIcon.image = [UIImage imageNamed:@"Alpha3_UnselectedIcon"];
- }
- return _selectStatusIcon;
- }
- - (void)setCardSelected:(BOOL)selected {
- _isSelected = selected;
-
- self.selectStatusIcon.image = selected ? [UIImage imageNamed:@"Alpha3_SelectedIcon"] : [UIImage imageNamed:@"Alpha3_UnselectedIcon"];
- if (self.clickCallback) {
- self.clickCallback(self, (int)self.tag, self.isSelected);
- }
- }
- - (void)setCellEditStatus:(BOOL)isEditing {
- if (isEditing) {
- self.overlayerView.hidden = NO;
- } else {
- self.overlayerView.hidden = YES;
- }
- }
- #pragma mark - Layout
- - (void)layoutAllCompoments {
- WeakSelf(weakSelf);
- [self.contentView addSubview:self.bgView];
- [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(weakSelf.contentView);
- make.right.equalTo(weakSelf.contentView);
- make.top.equalTo(weakSelf.contentView).with.offset(10);
- make.bottom.equalTo(weakSelf.contentView).with.offset(0);
- }];
-
- [self.bgView addSubview:self.photoImageView];
- [self.photoImageView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(weakSelf.bgView).with.offset(10);
- make.centerY.equalTo(weakSelf.bgView);
- make.size.mas_equalTo(CGSizeMake(102, 102));
- }];
-
- [self.bgView addSubview:self.descLabel];
- [self.descLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(weakSelf.photoImageView.mas_right).with.offset(10);
- make.right.equalTo(weakSelf.bgView).with.offset(-18);
- make.top.equalTo(weakSelf.bgView).with.offset(18);
- make.height.mas_equalTo(60);
- }];
-
- [self.bgView addSubview:self.estimatePriceLabel];
- [self.estimatePriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(weakSelf.photoImageView.mas_right).with.offset(10);
- make.right.equalTo(weakSelf.bgView).with.offset(-10);
- make.bottom.equalTo(weakSelf.bgView).with.offset(-18);
- make.height.mas_equalTo(18);
- }];
-
- [self layoutIfCellForEditable];
- }
- - (void)layoutIfCellForEditable {
- WeakSelf(weakSelf);
-
- self.overlayerView.hidden = YES;
- [self.bgView addSubview:self.overlayerView];
- [self.overlayerView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(weakSelf.contentView);
- make.right.equalTo(weakSelf.contentView);
- make.top.equalTo(weakSelf.contentView);
- make.bottom.equalTo(weakSelf.contentView);
- }];
- }
- #pragma mark - Helper
- - (void)setAttributedEstimatePrice:(NSString *)price {
- if (!price || price.length == 0) {
- self.estimatePriceLabel.text = @"";
- return;
- }
-
- self.estimatePriceLabel.text = [NSString stringWithFormat:@"¥ %@", price];
- }
- + (CGFloat)height {
- return 118 + 10;
- }
- @end
|