HomeSchoolHeadView.m 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. //
  2. // HomeSchoolHeadView.m
  3. // smartRhino
  4. //
  5. // Created by niuzhen on 2020/9/19.
  6. // Copyright © 2020 tederen. All rights reserved.
  7. //
  8. #import "HomeSchoolHeadView.h"
  9. @implementation HomeSchoolHeadView
  10. - (instancetype)init
  11. {
  12. if (self = [super init]) {
  13. [self setUpSubView];
  14. }
  15. return self;
  16. }
  17. - (void)setUpSubView
  18. {
  19. self.backgroundColor = UIColorHex(0xFFFFFF);
  20. [self addSubview:self.imagV];
  21. [self addSubview:self.showView];
  22. [self.imagV addSubview:self.playBtn];
  23. [self.showView addSubview:self.titleL];
  24. [self.showView addSubview:self.subTitleL];
  25. [self.showView addSubview:self.addressL];
  26. [self.showView addSubview:self.numL];
  27. [self.showView addSubview:self.typeL];
  28. [self.showView addSubview:self.collectBtn];
  29. [self.showView addSubview:self.iconV];
  30. self.showView.layer.shadowColor = UIColorHex(0x666666).CGColor;
  31. self.showView.layer.shadowOffset = CGSizeMake(2, 2);
  32. self.showView.layer.shadowOpacity = 8.f;
  33. self.showView.layer.shadowRadius = 10.f;
  34. [self.imagV mas_makeConstraints:^(MASConstraintMaker *make) {
  35. make.left.top.right.mas_equalTo(self);
  36. make.height.mas_offset(183 * SCREEN_WIDTH / 375);
  37. }];
  38. [self.playBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  39. make.centerX.mas_equalTo(self.imagV);
  40. make.top.mas_offset(40);
  41. make.size.mas_offset(CGSizeMake(55, 55));
  42. }];
  43. [self.showView mas_makeConstraints:^(MASConstraintMaker *make) {
  44. make.left.mas_offset(15);
  45. make.right.mas_offset(-15);
  46. make.height.mas_offset(93);
  47. make.bottom.mas_offset(-6);
  48. }];
  49. [self.iconV mas_makeConstraints:^(MASConstraintMaker *make) {
  50. make.left.top.mas_offset(15);
  51. make.size.mas_offset(CGSizeMake(63, 63));
  52. }];
  53. [self.collectBtn mas_makeConstraints:^(MASConstraintMaker *make) {
  54. make.top.mas_offset(15);
  55. make.right.mas_offset(-15);
  56. make.size.mas_offset(CGSizeMake(50, 26));
  57. }];
  58. [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
  59. make.left.mas_equalTo(self.iconV.mas_right).offset(15);
  60. make.top.mas_equalTo(self.iconV.mas_top);
  61. make.right.mas_equalTo(self.collectBtn.mas_left).offset(15);
  62. }];
  63. [self.subTitleL mas_makeConstraints:^(MASConstraintMaker *make) {
  64. make.left.mas_equalTo(self.titleL.mas_left);
  65. make.top.mas_equalTo(self.titleL.mas_bottom).offset(9);
  66. make.right.mas_equalTo(self.titleL.mas_right);
  67. }];
  68. }
  69. - (void)setDataWithModel:(HomeSubItemModel *)model
  70. {
  71. if (ISEmpty(model.VideoCoverImage)) {
  72. [self.imagV sd_setImageWithURL:[NSURL URLWithString:model.VideoImage] placeholderImage:kPlaceHolderImage];
  73. }else{
  74. [self.imagV sd_setImageWithURL:[NSURL URLWithString:model.VideoCoverImage] placeholderImage:kPlaceHolderImage];
  75. }
  76. [self.iconV sd_setImageWithURL:[NSURL URLWithString:model.ImageUrl] placeholderImage:kPlaceHolderImage];
  77. NSArray * array = model.LableName;
  78. if (array.count == 3) {
  79. self.addressL.text = array[0];
  80. self.numL.text = array[1];
  81. self.typeL.text = array[2];
  82. }
  83. self.titleL.text = model.Name;
  84. self.subTitleL.text = model.ExtendLableName;
  85. [self.collectBtn setTitle:model.IsCollect ? @"已收藏" : @"收藏" forState:UIControlStateNormal];
  86. [self.collectBtn setBackgroundColor:model.IsCollect ? UIColorHex(0x666666) : UIColorHex(0xFAC364)];
  87. [self.addressL mas_makeConstraints:^(MASConstraintMaker *make) {
  88. make.left.mas_equalTo(self.titleL.mas_left);
  89. make.top.mas_equalTo(self.subTitleL.mas_bottom).offset(9);
  90. make.size.mas_offset(CGSizeMake([self countLabel:self.addressL], 18));
  91. }];
  92. [self.numL mas_makeConstraints:^(MASConstraintMaker *make) {
  93. make.left.mas_equalTo(self.addressL.mas_right).offset(5);
  94. make.top.mas_equalTo(self.addressL.mas_top);
  95. make.size.mas_offset(CGSizeMake([self countLabel:self.numL], 18));
  96. }];
  97. [self.typeL mas_makeConstraints:^(MASConstraintMaker *make) {
  98. make.left.mas_equalTo(self.numL.mas_right).offset(5);
  99. make.top.mas_equalTo(self.addressL.mas_top);
  100. make.size.mas_offset(CGSizeMake([self countLabel:self.typeL], 18));
  101. }];
  102. self.imagV.userInteractionEnabled = YES;
  103. }
  104. - (CGFloat)countLabel:(UILabel *)label
  105. {
  106. CGFloat W = [label sizeThatFits:CGSizeMake(MAXFLOAT, 18)].width + 16.f;
  107. return W;
  108. }
  109. #pragma mark - SubView
  110. - (UIImageView *)imagV
  111. {
  112. if (!_imagV) {
  113. _imagV = [UIImageView new];
  114. // _imagV.contentMode = UIViewContentModeScaleAspectFill;
  115. }
  116. return _imagV;
  117. }
  118. - (UIImageView *)iconV
  119. {
  120. if (!_iconV) {
  121. _iconV = [UIImageView new];
  122. _iconV.layer.cornerRadius = 4.f;
  123. _iconV.layer.masksToBounds = YES;
  124. }
  125. return _iconV;
  126. }
  127. - (UIView *)showView
  128. {
  129. if (!_showView) {
  130. _showView = [UIView new];
  131. _showView.layer.cornerRadius = 12.f;
  132. _showView.layer.masksToBounds = YES;
  133. _showView.backgroundColor = UIColorHex(0xFFFFFF);
  134. }
  135. return _showView;
  136. }
  137. - (UILabel *)titleL
  138. {
  139. if (!_titleL) {
  140. _titleL = [UILabel new];
  141. _titleL.font = [UIFont systemFontOfSize:15];
  142. _titleL.textColor = UIColorHex(0x222222);
  143. }
  144. return _titleL;
  145. }
  146. - (UILabel *)subTitleL
  147. {
  148. if (!_subTitleL) {
  149. _subTitleL = [UILabel new];
  150. _subTitleL.font = [UIFont systemFontOfSize:12];
  151. _subTitleL.textColor = UIColorHex(0x222222);
  152. }
  153. return _subTitleL;
  154. }
  155. - (UILabel *)addressL
  156. {
  157. if (!_addressL) {
  158. _addressL = [UILabel new];
  159. _addressL.font = [UIFont systemFontOfSize:10];
  160. _addressL.textColor = UIColorHex(0x666666);
  161. _addressL.backgroundColor = UIColorHex(0xF4F4F4);
  162. _addressL.layer.cornerRadius = 2.f;
  163. _addressL.textAlignment = NSTextAlignmentCenter;
  164. _addressL.layer.masksToBounds = YES;
  165. }
  166. return _addressL;
  167. }
  168. - (UILabel *)numL
  169. {
  170. if (!_numL) {
  171. _numL = [UILabel new];
  172. _numL.font = [UIFont systemFontOfSize:10];
  173. _numL.textColor = UIColorHex(0x666666);
  174. _numL.backgroundColor = UIColorHex(0xF4F4F4);
  175. _numL.layer.cornerRadius = 2.f;
  176. _numL.textAlignment = NSTextAlignmentCenter;
  177. _numL.layer.masksToBounds = YES;
  178. }
  179. return _numL;
  180. }
  181. - (UILabel *)typeL
  182. {
  183. if (!_typeL) {
  184. _typeL = [UILabel new];
  185. _typeL.font = [UIFont systemFontOfSize:10];
  186. _typeL.textColor = UIColorHex(0x666666);
  187. _typeL.backgroundColor = UIColorHex(0xF4F4F4);
  188. _typeL.layer.cornerRadius = 2.f;
  189. _typeL.textAlignment = NSTextAlignmentCenter;
  190. _typeL.layer.masksToBounds = YES;
  191. }
  192. return _typeL;
  193. }
  194. - (UIButton *)collectBtn
  195. {
  196. if (!_collectBtn) {
  197. _collectBtn = [UIButton new];
  198. [_collectBtn setTitle:@"收藏" forState:UIControlStateNormal];
  199. [_collectBtn setBackgroundColor:UIColorHex(0xFAC364)];
  200. _collectBtn.titleLabel.font = [UIFont systemFontOfSize:14];
  201. [_collectBtn setTitleColor:UIColorHex(0xFFFFFF) forState:UIControlStateNormal];
  202. _collectBtn.layer.cornerRadius = 4.f;
  203. _collectBtn.layer.masksToBounds = YES;
  204. }
  205. return _collectBtn;
  206. }
  207. - (UIButton *)playBtn
  208. {
  209. if (!_playBtn) {
  210. _playBtn = [UIButton new];
  211. [_playBtn setImage:IMG(@"HomeSchool_Play") forState:UIControlStateNormal];
  212. }
  213. return _playBtn;
  214. }
  215. @end