BAGridCollectionCell.m 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. //
  2. // BAGridCollectionCell.m
  3. // BAKit
  4. //
  5. // Created by boai on 2017/4/14.
  6. // Copyright © 2017年 boaihome. All rights reserved.
  7. //
  8. #import "BAGridCollectionCell.h"
  9. #import "BAGridItemModel.h"
  10. #import "BAKit_ConfigurationDefine.h"
  11. #import "NSString+BAGridView.h"
  12. #import <SDWebImage/UIImageView+WebCache.h>
  13. @interface BAGridCollectionCell ()
  14. @property(nonatomic, strong) UIImageView *imageView;
  15. @property(nonatomic, strong) UILabel *titleLabel;
  16. @property(nonatomic, strong) UIView *lineView_w;
  17. @property(nonatomic, strong) UIView *lineView_h;
  18. @end
  19. @implementation BAGridCollectionCell
  20. - (instancetype)initWithFrame:(CGRect)frame
  21. {
  22. if (self = [super initWithFrame:frame])
  23. {
  24. [self setupUI];
  25. }
  26. return self;
  27. }
  28. - (void)setupUI
  29. {
  30. self.titleLabel.hidden = NO;
  31. self.imageView.hidden = NO;
  32. self.lineView_w.backgroundColor = BAKit_Color_Gray_11_pod;
  33. self.lineView_h.backgroundColor = BAKit_Color_Gray_11_pod;
  34. }
  35. - (void)layoutSubviews
  36. {
  37. [super layoutSubviews];
  38. CGFloat view_w = self.bounds.size.width;
  39. CGFloat view_h = self.bounds.size.height;
  40. CGFloat min_x = 0;
  41. CGFloat min_y = 0;
  42. CGFloat min_w = 0;
  43. CGFloat min_h = 0;
  44. min_w = view_h * 0.4;
  45. min_h = min_w;
  46. min_x = (view_w - min_w) / 2;
  47. min_y = CGRectGetMidY(self.bounds) - min_w / 2 - view_h * 0.15;
  48. self.imageView.frame = BAKit_CGRectFlatMake_pod(min_x, min_y, min_w, min_h);
  49. min_x = 0;
  50. min_y = CGRectGetMaxY(self.imageView.frame) + self.ba_gridView_itemImageInset;
  51. min_w = view_w - self.ba_gridView_lineWidth;
  52. min_h = view_h - min_y;
  53. self.titleLabel.frame = BAKit_CGRectFlatMake_pod(min_x, min_y, min_w, min_h);
  54. min_x = view_w - self.ba_gridView_lineWidth;
  55. min_y = 0;
  56. min_w = self.ba_gridView_lineWidth;
  57. min_h = view_h;
  58. self.lineView_h.frame = BAKit_CGRectFlatMake_pod(min_x, min_y, min_w, min_h);
  59. min_x = 0;
  60. min_y = view_h - self.ba_gridView_lineWidth;
  61. min_w = view_w;
  62. min_h = self.ba_gridView_lineWidth;
  63. self.lineView_w.frame = BAKit_CGRectFlatMake_pod(min_x, min_y, min_w, min_h);
  64. }
  65. #pragma mark - setter / getter
  66. - (UILabel *)titleLabel
  67. {
  68. if (!_titleLabel)
  69. {
  70. _titleLabel = [UILabel new];
  71. _titleLabel.textAlignment = NSTextAlignmentCenter;
  72. _titleLabel.font = [UIFont systemFontOfSize:16];
  73. [self.contentView addSubview:_titleLabel];
  74. }
  75. return _titleLabel;
  76. }
  77. - (UIImageView *)imageView
  78. {
  79. if (!_imageView)
  80. {
  81. _imageView = [UIImageView new];
  82. _imageView.backgroundColor = BAKit_Color_Clear_pod;
  83. [self.contentView addSubview:_imageView];
  84. }
  85. return _imageView;
  86. }
  87. - (UIView *)lineView_w
  88. {
  89. if (!_lineView_w)
  90. {
  91. _lineView_w = [UIView new];
  92. [self.contentView addSubview:_lineView_w];
  93. }
  94. return _lineView_w;
  95. }
  96. - (UIView *)lineView_h
  97. {
  98. if (!_lineView_h)
  99. {
  100. _lineView_h = [UIView new];
  101. [self.contentView addSubview:_lineView_h];
  102. }
  103. return _lineView_h;
  104. }
  105. - (void)setModel:(BAGridItemModel *)model
  106. {
  107. _model = model;
  108. if ([NSString ba_regularIsUrl:model.imageName])
  109. {
  110. [self.imageView sd_setImageWithURL:[NSURL URLWithString:model.imageName] placeholderImage:BAKit_ImageName(model.placdholderImageName)];
  111. }
  112. else
  113. {
  114. self.imageView.image = BAKit_ImageName(model.imageName);
  115. }
  116. self.titleLabel.text = model.titleString;
  117. }
  118. - (void)setBa_gridView_titleColor:(UIColor *)ba_gridView_titleColor
  119. {
  120. _ba_gridView_titleColor = ba_gridView_titleColor;
  121. self.titleLabel.textColor = ba_gridView_titleColor;
  122. }
  123. - (void)setBa_gridView_lineColor:(UIColor *)ba_gridView_lineColor
  124. {
  125. _ba_gridView_lineColor = ba_gridView_lineColor;
  126. self.lineView_w.backgroundColor = ba_gridView_lineColor;
  127. self.lineView_h.backgroundColor = ba_gridView_lineColor;
  128. }
  129. - (void)setBa_gridView_lineWidth:(CGFloat)ba_gridView_lineWidth
  130. {
  131. _ba_gridView_lineWidth = ba_gridView_lineWidth;
  132. }
  133. - (void)setBa_gridView_titleFont:(UIFont *)ba_gridView_titleFont
  134. {
  135. _ba_gridView_titleFont = ba_gridView_titleFont;
  136. self.titleLabel.font = ba_gridView_titleFont;
  137. }
  138. @end