HJFullTimeTableViewCell.m 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280
  1. //
  2. // HJFullTimeTableViewCell.m
  3. // HappyJob
  4. //
  5. // Created by Bob on 2019/3/15.
  6. // Copyright © 2019 Bob. All rights reserved.
  7. //
  8. #import "HJFullTimeTableViewCell.h"
  9. #import "UIButton+HJTagButton.h"
  10. @interface HJFullTimeTableViewCell () <FBFlowLayoutDelegate, FBFlowLayoutDataSource>
  11. @end
  12. @implementation HJFullTimeTableViewCell
  13. #pragma mark - life cycle
  14. - (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  15. if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
  16. {
  17. self.selectionStyle = UITableViewCellSelectionStyleNone;
  18. self.backgroundColor = COLOR_F5F5F5;
  19. _edgeInsets = UIEdgeInsetsMake(0, 0, 5, 0);
  20. [self.contentView addSubview:self.bgView];
  21. [self.contentView addSubview:self.titleLabel];
  22. [self.contentView addSubview:self.moneyLabel];
  23. [self.contentView addSubview:self.companyLabel];
  24. [self.contentView addSubview:self.addressLabel];
  25. [self.contentView addSubview:self.welfareView];
  26. [self.contentView addSubview:self.openBtn];
  27. [self.contentView addSubview:self.maxMoneyLabel];
  28. [self.contentView addSubview:self.dateLabel];
  29. [self.contentView addSubview:self.typeIconImageV];
  30. [self makeConstraints];
  31. }
  32. return self;
  33. }
  34. - (void)makeConstraints {
  35. [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  36. make.edges.equalTo(self.contentView).with.insets(self.edgeInsets);
  37. }];
  38. [self.typeIconImageV mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.left.top.offset(0);
  40. }];
  41. [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  42. make.top.left.equalTo(self.bgView).offset(15);
  43. }];
  44. [self.moneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  45. make.right.equalTo(self.bgView).offset(-15);
  46. make.centerY.equalTo(self.titleLabel);
  47. make.left.greaterThanOrEqualTo(self.titleLabel.mas_right);
  48. make.width.mas_greaterThanOrEqualTo(120);
  49. }];
  50. [self.companyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.top.equalTo(self.titleLabel.mas_bottom).with.offset(5);
  52. make.left.equalTo(self.bgView).offset(15);
  53. make.right.equalTo(self).offset(-100);
  54. }];
  55. [self.dateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.centerY.equalTo(self.companyLabel);
  57. make.right.equalTo(self.bgView).offset(-15);
  58. }];
  59. [self.addressLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.top.equalTo(self.companyLabel.mas_bottom).offset(5);
  61. make.left.equalTo(self.companyLabel);
  62. make.right.equalTo(self.bgView).offset(-15);
  63. }];
  64. [self.maxMoneyLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  65. make.top.equalTo(self.addressLabel.mas_bottom).offset(10);
  66. make.left.equalTo(self.titleLabel);
  67. }];
  68. [self.welfareView mas_makeConstraints:^(MASConstraintMaker *make) {
  69. make.left.equalTo(self.bgView).offset(15);
  70. make.right.equalTo(self.bgView).offset(-35);
  71. make.top.equalTo(self.maxMoneyLabel.mas_bottom).offset(10);
  72. }];
  73. [self.openBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  74. make.top.equalTo(self.welfareView.mas_top).offset(0);
  75. make.right.equalTo(self.mas_right).offset(-15);
  76. make.size.mas_offset(CGSizeMake(20, 20));//20
  77. }];
  78. [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
  79. make.bottom.equalTo(self.welfareView).offset(20);
  80. }];
  81. }
  82. #pragma mark - CustomDelegate
  83. - (CGFloat)estimateWidthInFlowLayoutView:(FBFlowLayoutView *)flowLayoutView {
  84. //宽
  85. return (SCREEN_WIDTH - 50);
  86. }
  87. - (CGFloat)subviewHorizontalSpacingInFlowLayoutView:(FBFlowLayoutView *)flowLayoutView {
  88. //水平间距
  89. return 5;
  90. }
  91. - (CGFloat)subviewVerticalSpacingInFlowLayoutView:(FBFlowLayoutView *)flowLayoutView {
  92. //上下间距
  93. return 6;
  94. }
  95. - (NSUInteger)numberInFlowLayoutView:(FBFlowLayoutView *)flowLayoutView {
  96. //返回多少个
  97. return self.welfareTagArray.count;
  98. }
  99. - (UIView *)flowLayoutView:(FBFlowLayoutView *)flowLayoutView subviewAtIndex:(NSUInteger)index {
  100. NSString *title = self.welfareTagArray[index];
  101. UIButton *tagButton = [UIButton hj_createWelfareTagButtonWithTitle:title maxSize:CGSizeMake(flowLayoutView.contentWidth, MAXFLOAT)];
  102. return tagButton;
  103. }
  104. #pragma mark - private methods
  105. #pragma mark - event respone
  106. - (void)openBtnClick:(UIButton *)btn {
  107. self.openBlock();
  108. }
  109. #pragma mark - getters and setters
  110. - (void)setWelfareTagArray:(NSArray *)welfareTagArray {
  111. _welfareTagArray = [welfareTagArray copy];
  112. [self.welfareView reloadData];
  113. if (welfareTagArray.count <= 0)
  114. {
  115. self.openBtn.hidden = YES;
  116. }
  117. else
  118. {
  119. self.openBtn.hidden = NO;
  120. }
  121. }
  122. - (void)setHiddenMaxMoneyLabel:(BOOL)hiddenMaxMoneyLabel {
  123. if (hiddenMaxMoneyLabel)
  124. {
  125. [self.welfareView mas_remakeConstraints:^(MASConstraintMaker *make) {
  126. make.left.equalTo(self.bgView).offset(15);
  127. make.right.equalTo(self.bgView).offset(-35);
  128. make.top.equalTo(self.addressLabel.mas_bottom).offset(10);
  129. }];
  130. }
  131. else
  132. {
  133. [self.welfareView mas_remakeConstraints:^(MASConstraintMaker *make) {
  134. make.left.equalTo(self.bgView).offset(15);
  135. make.right.equalTo(self.bgView).offset(-35);
  136. make.top.equalTo(self.maxMoneyLabel.mas_bottom).offset(10);
  137. }];
  138. }
  139. }
  140. - (UIView *)bgView {
  141. if (_bgView == nil)
  142. {
  143. _bgView = [[UIView alloc] init];
  144. _bgView.backgroundColor = [UIColor whiteColor];
  145. }
  146. return _bgView;
  147. }
  148. - (UIImageView *)typeIconImageV {
  149. if (_typeIconImageV == nil)
  150. {
  151. _typeIconImageV = [[UIImageView alloc]init];
  152. _typeIconImageV.contentMode = UIViewContentModeScaleAspectFill;
  153. _typeIconImageV.clipsToBounds = YES;
  154. }
  155. return _typeIconImageV;
  156. }
  157. - (UIButton *)openBtn {
  158. if (_openBtn == nil)
  159. {
  160. _openBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  161. [_openBtn addTarget:self action:@selector(openBtnClick:) forControlEvents:UIControlEventTouchUpInside];
  162. }
  163. return _openBtn;
  164. }
  165. - (FBFlowLayoutView *)welfareView {
  166. if (_welfareView == nil)
  167. {
  168. _welfareView = [[FBFlowLayoutView alloc] init];
  169. _welfareView.delegate = self;
  170. _welfareView.dataSource = self;
  171. }
  172. return _welfareView;
  173. }
  174. - (UILabel *)titleLabel {
  175. if (_titleLabel == nil)
  176. {
  177. _titleLabel = [[UILabel alloc] init];
  178. _titleLabel.textColor = COLOR_000000;
  179. _titleLabel.font = [UIFont boldSystemFontOfSize:19];
  180. _titleLabel.textAlignment = NSTextAlignmentLeft;
  181. }
  182. return _titleLabel;
  183. }
  184. - (UILabel *)moneyLabel {
  185. if (_moneyLabel == nil)
  186. {
  187. _moneyLabel = [[UILabel alloc] init];
  188. _moneyLabel.textColor = COLOR_FF401A;
  189. _moneyLabel.font = [UIFont boldSystemFontOfSize:16];
  190. _moneyLabel.textAlignment = NSTextAlignmentRight;
  191. [_moneyLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
  192. }
  193. return _moneyLabel;
  194. }
  195. - (UILabel *)companyLabel {
  196. if (_companyLabel == nil)
  197. {
  198. _companyLabel = [[UILabel alloc] init];
  199. _companyLabel.textColor = COLOR_444444;
  200. _companyLabel.font = [UIFont systemFontOfSize:13];
  201. _companyLabel.textAlignment = NSTextAlignmentLeft;
  202. [_companyLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
  203. }
  204. return _companyLabel;
  205. }
  206. - (UILabel *)addressLabel {
  207. if (_addressLabel == nil)
  208. {
  209. _addressLabel = [[UILabel alloc] init];
  210. _addressLabel.textColor = COLOR_444444;
  211. _addressLabel.font = [UIFont systemFontOfSize:13];
  212. // _addressLabel.textAlignment = NSTextAlignmentLeft;
  213. // [_addressLabel setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
  214. }
  215. return _addressLabel;
  216. }
  217. - (UILabel *)dateLabel {
  218. if (_dateLabel == nil)
  219. {
  220. _dateLabel = [[UILabel alloc] init];
  221. _dateLabel.textColor = COLOR_444444;
  222. _dateLabel.font = [UIFont systemFontOfSize:13];
  223. _dateLabel.textAlignment = NSTextAlignmentRight;
  224. }
  225. return _dateLabel;
  226. }
  227. - (HJMaxMoneyLabel *)maxMoneyLabel {
  228. if (_maxMoneyLabel == nil)
  229. {
  230. _maxMoneyLabel = [[HJMaxMoneyLabel alloc] init];
  231. _maxMoneyLabel.hidden = YES;
  232. }
  233. return _maxMoneyLabel;
  234. }
  235. @end