ResultISFCell.m 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. //
  2. // ResultISFCell.m
  3. // RA TradeFiling
  4. //
  5. // Created by Rui Zhang on 12/17/20.
  6. //
  7. #import "ResultISFCell.h"
  8. #import "const.h"
  9. #import "ResultAdditionView.h"
  10. #import "UIView+RAConstraint.h"
  11. @interface ResultISFCell ()
  12. @property (strong, nonatomic) IBOutlet UIView *bgView;
  13. @property (strong, nonatomic) IBOutlet UILabel *bolLabel;
  14. @property (strong, nonatomic) IBOutlet UILabel *transactionnoLabel;
  15. @property (strong, nonatomic) IBOutlet UILabel *isftypeLabel;
  16. @property (strong, nonatomic) IBOutlet UIImageView *iconView;
  17. @property (weak, nonatomic) IBOutlet UILabel *importnoLabel;
  18. @property (strong, nonatomic) IBOutlet UILabel *logLabel;
  19. @property (strong, nonatomic) IBOutlet UILabel *consigneeLabel;
  20. @property (nonatomic,strong) UIView *selectView;
  21. @property (nonatomic,assign) NSInteger additionCount;
  22. @property (nonatomic,strong) NSMutableArray<ResultAdditionView *> *additionArray;
  23. @end
  24. @implementation ResultISFCell
  25. #pragma mark - Override
  26. - (void)awakeFromNib {
  27. [super awakeFromNib];
  28. // Initialization code
  29. self.iconView.tintColor=UIColorFromRGB(0x1e7ffb);
  30. self.bgView.layer.cornerRadius = 10.0f;
  31. self.bgView.layer.borderColor = [UIColor darkGrayColor].CGColor;
  32. self.bgView.layer.borderWidth = 0.5f;
  33. self.bgView.layer.masksToBounds = YES;
  34. self.bgView.layer.shadowColor = [UIColor lightGrayColor].CGColor;
  35. self.bolLabel.textColor = [UIColor colorWithRed:53 / 255.0 green:53 / 255.0 blue:55 / 255.0 alpha:1.0];
  36. self.isftypeLabel.textColor = SecondaryTextColor;
  37. self.importnoLabel.textColor = SecondaryTextColor;
  38. // self.consigneeLabel.textColor = SecondaryTextColor;
  39. self.transactionnoLabel.textColor = [UIColor colorWithRed:53 / 255.0 green:53 / 255.0 blue:55 / 255.0 alpha:1.0];
  40. self.selectView = [UIView new];
  41. self.selectView.layer.cornerRadius = 5;
  42. self.selectView.layer.borderColor = [UIColor darkGrayColor].CGColor;
  43. self.selectView.layer.borderWidth = 0.3;
  44. self.selectView.backgroundColor = [UIColor colorWithWhite:0.7 alpha:0.8];
  45. self.selectedBackgroundView = self.selectView;
  46. self.additionArray = [NSMutableArray array];
  47. }
  48. - (void)layoutSubviews {
  49. [super layoutSubviews];
  50. self.selectView.frame = self.bgView.frame;
  51. }
  52. - (void)prepareForReuse {
  53. [super prepareForReuse];
  54. [[[[[[[[self setBOL:nil] setISFType:nil] setTransactionNo:nil] setLog:nil] setIcon:nil] setIconSelect:NO] setConsignee:nil] setImportNo:nil];
  55. [self clearAdditionView];
  56. }
  57. #pragma mark - Getter
  58. + (NSString *)identifier {
  59. return NSStringFromClass(self);
  60. }
  61. #pragma mark - Setter
  62. - (instancetype)setBOL:(NSString *)bol{
  63. self.bolLabel.text = bol;
  64. return self;
  65. }
  66. - (instancetype)setISFType:(NSString *)isftype{
  67. self.isftypeLabel.text = isftype;
  68. return self;
  69. }
  70. - (instancetype)setImportNo:(NSString *)import_no
  71. {
  72. self.importnoLabel.text = import_no;
  73. return self;
  74. }
  75. - (instancetype)setTransactionNo:(NSString *)transactionno{
  76. self.transactionnoLabel.text = transactionno;
  77. return self;
  78. }
  79. - (instancetype)setLog:(NSString *)log {
  80. self.logLabel.text = [log stringByReplacingOccurrencesOfString:@"," withString:@", "];
  81. return self;
  82. }
  83. - (instancetype)setIcon:(NSString *)icon {
  84. if (icon) {
  85. self.iconView.image = [[UIImage imageNamed:icon] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
  86. } else {
  87. self.iconView.image = nil;
  88. }
  89. return self;
  90. }
  91. - (instancetype)setIconSelect:(BOOL)select {
  92. if (select) {
  93. CGFloat w = CGRectGetWidth(self.iconView.bounds);
  94. CGFloat h = CGRectGetHeight(self.iconView.bounds);
  95. CGFloat r = MIN(w, h) * 0.5;
  96. UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:self.iconView.bounds cornerRadius:r];
  97. CAShapeLayer *mask = [CAShapeLayer layer];
  98. mask.lineWidth = 1.0f;
  99. mask.strokeColor = [UIColor redColor].CGColor;
  100. mask.fillColor = [UIColor clearColor].CGColor;
  101. mask.path = path.CGPath;
  102. mask.name = @"am_mask";
  103. [self.iconView.layer addSublayer:mask];
  104. } else {
  105. NSMutableArray *mArr = [self.iconView.layer.sublayers mutableCopy];
  106. for (CALayer *layer in mArr) {
  107. if ([layer isKindOfClass:[CAShapeLayer class]] && [layer.name isEqualToString:@"am_mask"]) {
  108. [layer removeFromSuperlayer];
  109. }
  110. }
  111. }
  112. return self;
  113. }
  114. - (instancetype)setConsignee:(NSString *)consignee {
  115. self.consigneeLabel.text = consignee;
  116. return self;
  117. }
  118. - (instancetype)addAdditionName:(NSString *)name value:(NSString *)value {
  119. ResultAdditionView *additionView;
  120. if (self.additionCount >= self.additionArray.count) {
  121. additionView = [ResultAdditionView additionView];
  122. [self.additionArray addObject:additionView];
  123. } else {
  124. additionView = [self.additionArray objectAtIndex:self.additionCount];
  125. }
  126. additionView.titleLabel.text = name;
  127. additionView.valueLabel.text = value;
  128. [self.bgView addSubview:additionView];
  129. __weak typeof(self) weakSelf = self;
  130. [additionView ra_applyConstraints:^(RAConstraintMaker *maker) {
  131. maker.left.ra_equalTo(weakSelf.bgView.left).ra_offset(10);
  132. maker.top.ra_equalTo(weakSelf.bgView.top).ra_offset(110.0f + 25.0f * weakSelf.additionCount);
  133. maker.right.ra_equalTo(weakSelf.bgView.right).ra_offset(-10);
  134. maker.height.ra_offset(25.0f);
  135. }];
  136. self.additionCount++;
  137. return self;
  138. }
  139. #pragma mark - Private
  140. - (void)clearAdditionView {
  141. for (ResultAdditionView *additionView in self.additionArray) {
  142. [additionView removeFromSuperview];
  143. }
  144. self.additionCount = 0;
  145. }
  146. @end