MGNewDTHeadView.m 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. //
  2. // MGNewDTHeadView.m
  3. // BuguLive
  4. //
  5. // Created by 宋晨光 on 2019/11/26.
  6. // Copyright © 2019 xfg. All rights reserved.
  7. //
  8. #import "MGNewDTHeadView.h"
  9. @implementation MGNewDTHeadView
  10. - (instancetype)initWithFrame:(CGRect)frame
  11. {
  12. self = [super initWithFrame:frame];
  13. if (self) {
  14. [self setUpView];
  15. }
  16. return self;
  17. }
  18. -(void)setUpView{
  19. // self.firstView = [self addViewWithTitleScrollView];
  20. self.topicView = [self setUpTopicView];
  21. self.topicView.top = 0;
  22. // self.firstView.bottom;
  23. // [self addSubview:self.firstView];
  24. [self addSubview:self.topicView];
  25. self.backgroundColor = kWhiteColor;
  26. }
  27. -(UIView *)addViewWithTitleScrollView{
  28. UIView *firstView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kRealValue(90))];
  29. CGFloat viewWidth = kRealValue(184);
  30. for (int i = 0 ; i < 2; i ++) {
  31. UIControl *control = [[UIControl alloc]initWithFrame:CGRectMake(kRealValue(4) + i * viewWidth , kRealValue(4), viewWidth, kRealValue(79))];
  32. control.tag = 10 + i;
  33. [control addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
  34. UIImageView *bgImgView = [[UIImageView alloc]initWithFrame:control.bounds];
  35. UILabel *titleL = [UILabel new];
  36. UILabel *subTitleL = [UILabel new];
  37. titleL.text = i == 0 ? ASLocalizedString(@"直播"): ASLocalizedString(@"短视频");
  38. titleL.textColor = [UIColor colorWithHexString:@"#333333"];
  39. titleL.font = [FontHelper fontWithSize:16];
  40. titleL.frame = CGRectMake(kRealValue(15), kRealValue(15), viewWidth, kRealValue(22));
  41. subTitleL.text = i == 0 ? ASLocalizedString(@"美女live"): ASLocalizedString(@"美女live");
  42. subTitleL.textColor = [UIColor colorWithHexString:@"#666666"];
  43. subTitleL.font = [FontHelper fontWithSize:13];
  44. subTitleL.frame = CGRectMake(titleL.left, titleL.bottom + kRealValue(5), kRealValue(60), kRealValue(20));
  45. UIImageView *imgView = [[UIImageView alloc]initWithFrame:CGRectMake(control.width / 2 + kRealValue(10), control.height / 2, kRealValue(42), kRealValue(37))];
  46. if (i == 0) {
  47. [bgImgView setImage:[UIImage imageNamed:@"dy_head_live_BGImg"]];
  48. imgView.image = [UIImage imageNamed:@"dy_head_live_img"];
  49. }else{
  50. [bgImgView setImage:[UIImage imageNamed:@"dy_head_short_BGImg"]];
  51. imgView.image = [UIImage imageNamed:@"dy_head_short_img"];
  52. imgView.width = kRealValue(40);
  53. imgView.height = kRealValue(40);
  54. }
  55. imgView.centerY = control.height / 2;
  56. [control addSubview:bgImgView];
  57. [control addSubview:titleL];
  58. [control addSubview:subTitleL];
  59. [control addSubview:imgView];
  60. [firstView addSubview:control];
  61. }
  62. return firstView;
  63. }
  64. -(UIView *)setUpTopicView{
  65. UIView *topicView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, kRealValue(160))];
  66. // UILabel *topicL = [[UILabel alloc]initWithFrame:CGRectMake(kRealValue(10), kRealValue(13), kRealValue(50), kRealValue(20))];
  67. // topicL.text = ASLocalizedString(@"话题");
  68. // topicL.font = [UIFont systemFontOfSize:17];
  69. // topicL.textColor = kBlackColor;
  70. //
  71. // UIButton *topicBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  72. // topicBtn.frame = CGRectMake(kScreenW - kRealValue(80) - kRealValue(5), 0, kRealValue(80), kRealValue(20));
  73. // topicBtn.centerY = topicL.centerY;
  74. // topicBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentRight;
  75. // topicBtn.tag = 1000;
  76. // [topicBtn setTitle:ASLocalizedString(@"全部话题")forState:UIControlStateNormal];
  77. // [topicBtn setTitleColor:[UIColor colorWithHexString:@"#666666"] forState:UIControlStateNormal];
  78. // [topicBtn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
  79. // topicBtn.titleLabel.font = [UIFont systemFontOfSize:16];
  80. CGFloat viewWidth = kRealValue(116);
  81. CGFloat viewHeight = kRealValue(116);
  82. UIScrollView *scrollView = [UIScrollView new];
  83. scrollView.frame = CGRectMake(kRealValue(4), kRealValue(10), kScreenW - kRealValue(4 * 2), viewHeight + kRealValue(10));
  84. scrollView.contentSize = CGSizeMake(viewWidth * 4 + kRealValue(15 * 3), 0);
  85. scrollView.showsHorizontalScrollIndicator = NO;
  86. // [topicView addSubview:topicL];
  87. // [topicView addSubview:topicBtn];
  88. [topicView addSubview:scrollView];
  89. for (int i = 0 ; i < 4; i ++) {
  90. MGNewDTHeadControl *control = [[MGNewDTHeadControl alloc]initWithFrame:CGRectMake(kRealValue(4) + i * (viewWidth + kRealValue(10)) ,0, viewWidth, viewHeight)];
  91. control.tag = 100 + i;
  92. control.layer.masksToBounds = YES;
  93. control.layer.cornerRadius = 4;
  94. [scrollView addSubview:control];
  95. }
  96. return topicView;
  97. }
  98. -(void)clickBtn:(UIButton *)sender{
  99. if (sender.tag == 10) {//点击直播
  100. [AppDelegate sharedAppDelegate].topViewController.tabBarController.selectedIndex = 0;
  101. }else if (sender.tag == 11) {//点击短视频
  102. [AppDelegate sharedAppDelegate].topViewController.tabBarController.selectedIndex = 2;
  103. }else if (sender.tag == 1000) {//全部话题
  104. if (self.MGNewDTHeadViewTopicBlock) {
  105. self.MGNewDTHeadViewTopicBlock(sender.tag);
  106. }
  107. }else if (sender.tag == 10) {
  108. }else if (sender.tag == 10) {
  109. }else{
  110. }
  111. }
  112. -(void)resetTopicModel:(NSArray *)arr{
  113. self.topicArr = [NSMutableArray arrayWithArray:arr];
  114. for (int i = 0; i < 4; i ++) {
  115. if (i > 4) return;
  116. MGNewDTHeadControl *control = [self.topicView viewWithTag:100 + i];
  117. if(arr.count > i)
  118. {
  119. [control resetControlModel:arr[i]];
  120. //给有数据的view添加手势
  121. [control addTarget:self action:@selector(MGNewDTHeadAction:) forControlEvents:UIControlEventTouchUpInside];
  122. }
  123. }
  124. }
  125. - (void)MGNewDTHeadAction:(UIControl *)sender{
  126. if (self.MGNewDTHeadViewTopicBlock) {
  127. self.MGNewDTHeadViewTopicBlock(sender.tag-100);
  128. }
  129. }
  130. -(UIScrollView *)titleScroll{
  131. if (!_titleScroll) {
  132. _titleScroll = [UIScrollView new];
  133. }
  134. return _titleScroll;
  135. }
  136. @end
  137. @implementation MGNewDTHeadControl
  138. - (instancetype)initWithFrame:(CGRect)frame
  139. {
  140. self = [super initWithFrame:frame];
  141. if (self) {
  142. [self setUpViewWithFrame:frame];
  143. _timeL.hidden = YES;
  144. }
  145. return self;
  146. }
  147. -(void)resetControlModel:(MGDynamicTopicModel *)model{
  148. [_topicTitleBtn setTitle:[NSString stringWithFormat:@" %@ ",model.name] forState:UIControlStateNormal];
  149. _topicTitleBtn.titleLabel.lineBreakMode = NSLineBreakByTruncatingTail;
  150. _timeL.text = [NSString stringWithFormat:ASLocalizedString(@"%@人参与了该话题"),model.num];
  151. [_bgImgView sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:nil];
  152. }
  153. -(void)setUpViewWithFrame:(CGRect)frame{
  154. UIImageView *bgImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, frame.size.width, frame.size.height)];
  155. bgImgView.image = [UIImage imageNamed:@"dy_head_topic_BGImg"];
  156. bgImgView.contentMode = UIViewContentModeScaleAspectFill;
  157. _bgImgView = bgImgView;
  158. QMUIButton *topicTitleBtn = [QMUIButton buttonWithType:UIButtonTypeCustom];
  159. // [topicTitleBtn setImage:[UIImage imageNamed:@"dy_head_topic"] forState:UIControlStateNormal];
  160. // topicTitleBtn.imagePosition = QMUIButtonImagePositionLeft;
  161. // topicTitleBtn.spacingBetweenImageAndTitle = 2;
  162. topicTitleBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
  163. [topicTitleBtn setTitle:ASLocalizedString(@"#大约在冬季#")forState:UIControlStateNormal];
  164. topicTitleBtn.userInteractionEnabled = NO;
  165. [topicTitleBtn setTitleColor:kBlackColor forState:UIControlStateNormal];
  166. topicTitleBtn.titleLabel.font = [UIFont systemFontOfSize:12];
  167. topicTitleBtn.backgroundColor = kWhiteColor;
  168. _topicTitleBtn = topicTitleBtn;
  169. UILabel *timeL = [UILabel new];
  170. timeL.text = ASLocalizedString(@"今日更新");
  171. timeL.font = [UIFont systemFontOfSize:12];
  172. timeL.textColor = kWhiteColor;
  173. _timeL = timeL;
  174. topicTitleBtn.frame = CGRectMake(kRealValue(5), self.height - kRealValue(5 + 20),bgImgView.width - kRealValue(10) * 2, kRealValue(20));
  175. topicTitleBtn.layer.cornerRadius = kRealValue(20 / 2);
  176. topicTitleBtn.layer.masksToBounds = YES;
  177. timeL.frame = CGRectMake(topicTitleBtn.left, topicTitleBtn.bottom + kRealValue(5), bgImgView.width - kRealValue(10) * 2, kRealValue(20));
  178. [self addSubview:bgImgView];
  179. [self addSubview:topicTitleBtn];
  180. [self addSubview:timeL];
  181. }
  182. @end