Keine Beschreibung

FKBookRecSingleView.m 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. // FKBookRecSingleView.m
  3. // FirstLink
  4. //
  5. // Created by jack on 16/4/28.
  6. // Copyright © 2016年 FirstLink. All rights reserved.
  7. //
  8. #import "FKBookRecSingleView.h"
  9. @implementation FKBookRecSingleView
  10. - (instancetype)initWithFrame:(CGRect)frame{
  11. if (self = [super initWithFrame:frame]) {
  12. [self addAllSubviews];
  13. [self addTapGesture];
  14. }
  15. return self;
  16. }
  17. - (void)addAllSubviews{
  18. self.backgroundColor = UIColorFromRGB(0xdbdbdb);
  19. [self addSubview:self.imageView];
  20. [self addSubview:self.priceLabel];
  21. [self.imageView mas_makeConstraints:^(MASConstraintMaker *make) {
  22. make.top.left.right.equalTo(self);
  23. make.height.equalTo(self.mas_width);
  24. }];
  25. [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  26. make.left.bottom.equalTo(self);
  27. make.height.mas_equalTo(20);
  28. make.right.equalTo(self).offset(- 10);
  29. }];
  30. }
  31. - (void)addTapGesture{
  32. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(singleTap)];
  33. [self addGestureRecognizer:tap];
  34. }
  35. - (void)fk_configWithModel:(FKBookRecProItem *)item{
  36. if ([item isKindOfClass:[FKBookRecProItem class]]){
  37. [self.imageView setImageWithURL:item.picUrl cdnWidth:100.0f];
  38. self.priceLabel.text = [NSString stringWithFormat:@"¥%@", [FLStringHelper convertFenToYuan:item.currentPrice]];
  39. self.productId = item.itemID;
  40. }
  41. }
  42. - (void)singleTap{
  43. if (self.clickAction){
  44. WeakSelf(weakSelf);
  45. self.clickAction(weakSelf);
  46. }
  47. }
  48. - (UIImageView *)imageView{
  49. if (_imageView == nil) {
  50. _imageView = [[UIImageView alloc]init];
  51. _imageView.contentMode = UIViewContentModeScaleAspectFit;
  52. _imageView.backgroundColor = [UIColor whiteColor];
  53. }
  54. return _imageView;
  55. }
  56. - (UILabel *)priceLabel{
  57. if (_priceLabel == nil) {
  58. _priceLabel = [[UILabel alloc]init];
  59. _priceLabel.textColor = UIColorFromRGB(0x333333);
  60. _priceLabel.font = [UIFont systemFontOfSize:12];
  61. _priceLabel.textAlignment = NSTextAlignmentRight;
  62. _priceLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  63. }
  64. return _priceLabel;
  65. }
  66. @end