// // FKProductRelativeView.m // FirstLink // // Created by jack on 16/5/24. // Copyright © 2016年 FirstLink. All rights reserved. // #import "FKProductRelativeView.h" #import "FKProductRelativeCell.h" @implementation FKProductRelativeView - (instancetype)initWithFrame:(CGRect)frame{ if (self = [super initWithFrame:frame]) { [self addAllSubviews]; } return self; } - (void)addAllSubviews{ [self addSubview:self.imageView]; [self addSubview:self.titleLabel]; [self addSubview:self.priceLabel]; [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.top.right.equalTo(self); make.height.equalTo(self.mas_width); }]; [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.imageView.mas_bottom).offset(8); make.left.right.equalTo(self.imageView); }]; [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.top.equalTo(self.titleLabel.mas_bottom).offset(8); make.left.right.equalTo(self.imageView); }]; } - (void)configWithRelativeItem:(FKProductRelativeItem *)item{ self.imageView.image = nil; self.titleLabel.text = nil; self.priceLabel.text = nil; if (item){ [self.imageView setImageWithURL:item.picUrl cdnWidth:[FKProductRelativeCell get_imageViewMargin]]; self.titleLabel.text = item.title; self.priceLabel.text = [NSString stringWithFormat:@"¥%.2f", [FLStringHelper convertFenStringToYuanValue:item.price]]; } } #pragma mark - property - (UIImageView *)imageView{ if (_imageView == nil) { _imageView = [[UIImageView alloc]init]; _imageView.contentMode = UIViewContentModeScaleAspectFit; } return _imageView; } - (UILabel *)titleLabel{ if (_titleLabel == nil) { _titleLabel = [[UILabel alloc]init]; _titleLabel.font = [UIFont systemFontOfSize:13]; _titleLabel.textColor = UIColorFromRGB(0x4a4a4a); _titleLabel.numberOfLines = 1; } return _titleLabel; } - (UILabel *)priceLabel{ if (_priceLabel == nil) { _priceLabel = [[UILabel alloc]init]; _priceLabel.font = [UIFont systemFontOfSize:13]; _priceLabel.textColor = UIColorFromRGB(0x4a4a4a); } return _priceLabel; } @end