123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- //
- // FKCircleProductCell.m
- // FirstLink
- //
- // Created by ascii on 16/6/14.
- // Copyright © 2016年 FirstLink. All rights reserved.
- //
- #import "FKCircleProductCell.h"
- #import <SDWebImage/UIImageView+WebCache.h>
- #import "FKCircleChoiceProductItem.h"
- @interface FKCircleProductCell ()
- @property (nonatomic, strong) UIImageView *productImgView;
- @property (nonatomic, strong) UILabel *titleLabel;
- @property (nonatomic, strong) UILabel *currentPriceLabel;
- @property (nonatomic, strong) UILabel *originPriceLabel;
- @property (nonatomic, strong) UIView *cutLine;
- @end
- @implementation FKCircleProductCell
- - (void)awakeFromNib {
- [super awakeFromNib];
- // Initialization code
- }
- - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
- if (self) {
- self.contentView.backgroundColor = [UIColor whiteColor];
-
- [self addAllSubviews];
- }
- return self;
- }
- - (void)setSelected:(BOOL)selected animated:(BOOL)animated {
- [super setSelected:selected animated:animated];
-
- // Configure the view for the selected state
- }
- - (void)configWithItem:(id)item {
- if ([item isKindOfClass:[FKCircleChoiceProductItem class]]) {
- FKCircleChoiceProductItem *productItem = (FKCircleChoiceProductItem*)item;
-
- [self.productImgView sd_setImageWithURL:[NSURL URLWithString:productItem.photoURL]];
- self.titleLabel.text = productItem.title;
- self.currentPriceLabel.text = [FLStringHelper convertFenToRMBmoneyString:productItem.price];
- self.originPriceLabel.text = nil;
- if ([FLStringHelper isValidString:productItem.originPrice]){
- self.originPriceLabel.text = [FLStringHelper convertFenToRMBmoneyString:productItem.originPrice];
- }
-
- self.choiceButton.selected = productItem.isSelected;
- }
- }
- #pragma mark - Method
- + (CGFloat)height {
- return 105;
- }
- #pragma mark - Layout
- - (void)addAllSubviews {
- [self.contentView addSubview:self.productImgView];
- [self.productImgView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.centerY.equalTo(self.contentView);
- make.left.equalTo(self.contentView).offset(5);
- make.size.mas_equalTo(CGSizeMake(95, 95));
- }];
-
- [self.contentView addSubview:self.titleLabel];
- [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.productImgView.mas_right).offset(10);
- make.top.equalTo(self.contentView).offset(20);
- make.right.equalTo(self.contentView).offset(-15);
- }];
-
- [self.contentView addSubview:self.currentPriceLabel];
- [self.currentPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.titleLabel);
- make.bottom.equalTo(self.contentView).offset(-22);
- }];
-
- [self.contentView addSubview:self.choiceButton];
- [self.choiceButton mas_makeConstraints:^(MASConstraintMaker *make) {
- make.right.equalTo(self.contentView).offset(-15);
- make.centerY.equalTo(self.currentPriceLabel);
- make.size.mas_equalTo(CGSizeMake(30, 30));
- }];
-
- [self.contentView addSubview:self.originPriceLabel];
- [self.originPriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
- make.left.equalTo(self.currentPriceLabel.mas_right).offset(2);
- make.baseline.equalTo(self.currentPriceLabel.mas_baseline);
- make.right.mas_lessThanOrEqualTo(self.choiceButton.mas_left);
- }];
-
- [self.contentView addSubview:self.cutLine];
- [self.cutLine mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.equalTo(self.originPriceLabel);
- make.width.mas_equalTo(self.originPriceLabel);
- make.height.mas_equalTo(0.5);
- }];
- }
- #pragma mark - Property
- - (UIImageView*)productImgView {
- if (!_productImgView) {
- _productImgView = [UIImageView new];
- _productImgView.contentMode = UIViewContentModeScaleAspectFit;
- _productImgView.backgroundColor = [UIColor whiteColor];
- }
- return _productImgView;
- }
- - (UILabel *)titleLabel {
- if (!_titleLabel) {
- _titleLabel = [[UILabel alloc] init];
- _titleLabel.textColor = UIColorFromRGB(0x333333);
- _titleLabel.font = [UIFont systemFontOfSize:14];
- _titleLabel.numberOfLines = 2;
- }
- return _titleLabel;
- }
- - (UILabel *)currentPriceLabel{
- if (_currentPriceLabel == nil) {
- _currentPriceLabel = [[UILabel alloc]init];
- _currentPriceLabel.textColor = UIColorFromRGB(0x333333);
- _currentPriceLabel.font = [UIFont boldSystemFontOfSize:15];
- }
- return _currentPriceLabel;
- }
- - (UILabel *)originPriceLabel{
- if (_originPriceLabel == nil) {
- _originPriceLabel = [[UILabel alloc]init];
- _originPriceLabel.font = [UIFont boldSystemFontOfSize:9];
- _originPriceLabel.textColor = UIColorFromRGB(0x666666);
- _originPriceLabel.lineBreakMode = NSLineBreakByTruncatingTail;
- }
- return _originPriceLabel;
- }
- - (UIButton *)choiceButton{
- if (_choiceButton == nil) {
- _choiceButton = [UIButton buttonWithType:UIButtonTypeCustom];
-
- [_choiceButton setImage:[UIImage imageNamed:@"basket_unSelect"] forState:UIControlStateNormal];
- [_choiceButton setImage:[UIImage imageNamed:@"basket_selected"] forState:UIControlStateSelected];
- }
- return _choiceButton;
- }
- - (UIView *)cutLine{
- if (_cutLine == nil) {
- _cutLine = [[UIView alloc]init];
- _cutLine.backgroundColor = UIColorFromRGB(0x666666);
- }
- return _cutLine;
- }
- @end
|