No Description

FKProductRelativeView.m 2.3KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // FKProductRelativeView.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/5/24.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKProductRelativeView.h"
  9. #import "FKProductRelativeCell.h"
  10. @implementation FKProductRelativeView
  11. - (instancetype)initWithFrame:(CGRect)frame{
  12. if (self = [super initWithFrame:frame]) {
  13. [self addAllSubviews];
  14. }
  15. return self;
  16. }
  17. - (void)addAllSubviews{
  18. [self addSubview:self.imageView];
  19. [self addSubview:self.titleLabel];
  20. [self addSubview:self.priceLabel];
  21. [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
  22. make.left.top.right.equalTo(self);
  23. make.height.equalTo(self.mas_width);
  24. }];
  25. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  26. make.top.equalTo(self.imageView.mas_bottom).offset(8);
  27. make.left.right.equalTo(self.imageView);
  28. }];
  29. [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  30. make.top.equalTo(self.titleLabel.mas_bottom).offset(8);
  31. make.left.right.equalTo(self.imageView);
  32. }];
  33. }
  34. - (void)configWithRelativeItem:(FKProductRelativeItem *)item{
  35. self.imageView.image = nil;
  36. self.titleLabel.text = nil;
  37. self.priceLabel.text = nil;
  38. if (item){
  39. [self.imageView setImageWithURL:item.picUrl cdnWidth:[FKProductRelativeCell get_imageViewMargin]];
  40. self.titleLabel.text = item.title;
  41. self.priceLabel.text = [NSString stringWithFormat:@"¥%.2f", [FLStringHelper convertFenStringToYuanValue:item.price]];
  42. }
  43. }
  44. #pragma mark - property
  45. - (UIImageView *)imageView{
  46. if (_imageView == nil) {
  47. _imageView = [[UIImageView alloc]init];
  48. _imageView.contentMode = UIViewContentModeScaleAspectFit;
  49. }
  50. return _imageView;
  51. }
  52. - (UILabel *)titleLabel{
  53. if (_titleLabel == nil) {
  54. _titleLabel = [[UILabel alloc]init];
  55. _titleLabel.font = [UIFont systemFontOfSize:13];
  56. _titleLabel.textColor = UIColorFromRGB(0x4a4a4a);
  57. _titleLabel.numberOfLines = 1;
  58. }
  59. return _titleLabel;
  60. }
  61. - (UILabel *)priceLabel{
  62. if (_priceLabel == nil) {
  63. _priceLabel = [[UILabel alloc]init];
  64. _priceLabel.font = [UIFont systemFontOfSize:13];
  65. _priceLabel.textColor = UIColorFromRGB(0x4a4a4a);
  66. }
  67. return _priceLabel;
  68. }
  69. @end