NewDynamicListShieldView.m 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  1. //
  2. // NewDynamicListShieldView.m
  3. // 乐销
  4. //
  5. // Created by liuhuiping on 2017/10/28.
  6. // Copyright © 2017年 ping. All rights reserved.
  7. //
  8. #import "NewDynamicListShieldView.h"
  9. @implementation NewDynamicListShieldView
  10. #pragma mark lazy
  11. - (UIScrollView *)shareScrollView{
  12. if (_shareScrollView == nil) {
  13. _shareScrollView = [UIScrollView new];
  14. _shareScrollView.frame = CGRectMake(W(0), W(0), SCREEN_WIDTH, W(123));
  15. _shareScrollView.contentSize = CGSizeMake(0, 0);
  16. _shareScrollView.backgroundColor = [UIColor whiteColor];
  17. _shareScrollView.showsHorizontalScrollIndicator = false;
  18. _shareScrollView.showsVerticalScrollIndicator = false;
  19. }
  20. return _shareScrollView;
  21. }
  22. - (DynamicListShieldHeaderView *)headerView {
  23. if (!_headerView) {
  24. _headerView = [DynamicListShieldHeaderView new];
  25. _headerView.frame = CGRectMake(W(0), W(0), SCREEN_WIDTH, self.headerView.height);
  26. _headerView.bottom = SCREEN_HEIGHT;
  27. [_headerView.control addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  28. }
  29. return _headerView;
  30. }
  31. - (NSArray *)shareAryDatas{
  32. if (!_shareAryDatas) {
  33. _shareAryDatas = @[[ModelBtn modelWithTitle:@"微信好友" imageName:@"wd_wx" highImageName:@"wd_wx" tag:0],[ModelBtn modelWithTitle:@"朋友圈" imageName:@"wd_pyq" highImageName:@"wd_pyq" tag:1]];
  34. }
  35. return _shareAryDatas;
  36. }
  37. #pragma mark 初始化
  38. - (instancetype)initWithFrame:(CGRect)frame{
  39. self = [super initWithFrame:frame];
  40. if (self) {
  41. [self addSubView];
  42. }
  43. return self;
  44. }
  45. //添加subview
  46. - (void)addSubView{
  47. self.backgroundColor = COLOR_BLACK_ALPHA_PER60;
  48. self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
  49. [self addSubview:self.shareScrollView];
  50. [self addSubview:self.headerView];
  51. [self addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
  52. }
  53. - (void)resetWithModel:(id)model{
  54. self.headerView.leftBottom =XY(0,SCREEN_HEIGHT);
  55. WEAKSELF
  56. if (isAry(self.shareAryDatas)) {
  57. self.shareScrollView.bottom = [self addLineFrame:CGRectMake(W(15), self.headerView.top, SCREEN_WIDTH-W(30), 1)];
  58. CGFloat left = 0;
  59. for (ModelBtn * model in self.shareAryDatas) {
  60. ShieldView * view = [ShieldView new];
  61. view.blockModel = ^(ModelBtn *modelBtn) {
  62. if (weakSelf.blockSelectBtnModel) {
  63. weakSelf.blockSelectBtnModel(modelBtn);
  64. [weakSelf removeFromSuperview];
  65. }
  66. };
  67. [view resetViewWithModel:model];
  68. view.left = left;
  69. left = view.right;
  70. [self.shareScrollView addSubview:view];
  71. self.shareScrollView.contentSize = CGSizeMake(left, 0);
  72. }
  73. }
  74. }
  75. #pragma mark btnClick
  76. - (void)btnClick:(UIButton *)sender{
  77. [self removeFromSuperview];
  78. }
  79. @end
  80. @implementation ShieldView
  81. #pragma mark 懒加载
  82. - (UIImageView *)imgView{
  83. if (_imgView == nil) {
  84. _imgView = [UIImageView new];
  85. _imgView.widthHeight = XY(W(60),W(60));
  86. }
  87. return _imgView;
  88. }
  89. - (UILabel *)labelName{
  90. if (_labelName == nil) {
  91. _labelName = [UILabel new];
  92. [GlobalMethod setLabel:_labelName widthLimit:0 numLines:0 fontNum:F(14) textColor:COLOR_LABEL text:@""];
  93. }
  94. return _labelName;
  95. }
  96. #pragma mark 初始化
  97. - (instancetype)initWithFrame:(CGRect)frame{
  98. self = [super initWithFrame:frame];
  99. if (self) {
  100. self.backgroundColor = [UIColor whiteColor];
  101. self.width = SCREEN_WIDTH;
  102. [self addSubView];
  103. }
  104. return self;
  105. }
  106. //添加subview
  107. - (void)addSubView{
  108. [self addSubview:self.imgView];
  109. [self addSubview:self.labelName];
  110. [self addTarget:self action:@selector(btnClick:) forControlEvents:(UIControlEventTouchUpInside)];
  111. //初始化页面
  112. [self resetViewWithModel:nil];
  113. }
  114. #pragma mark 刷新view
  115. - (void)resetViewWithModel:(ModelBtn *)model{
  116. self.model = model;
  117. [self removeSubViewWithTag:TAG_LINE];//移除线
  118. //刷新view
  119. self.imgView.image = [UIImage imageNamed:model.imageName];
  120. self.imgView.leftTop = XY(W(20),W(20));
  121. [self.labelName fitTitle:model.title variable:0];
  122. self.labelName.centerXTop = XY(self.imgView.centerX,self.imgView.bottom+W(10));
  123. self.labelName.textColor = model.color?model.color:COLOR_DETAIL;
  124. self.width = self.imgView.right;
  125. self.height = self.labelName.bottom+W(20);
  126. }
  127. #pragma mark click
  128. - (void)btnClick:(UIButton *)sender {
  129. if (self.blockModel) {
  130. self.blockModel(self.model);
  131. }
  132. }
  133. @end
  134. @implementation DynamicListShieldHeaderView
  135. #pragma mark 懒加载
  136. - (UIImageView *)imgView{
  137. if (_imgView == nil) {
  138. _imgView = [UIImageView new];
  139. _imgView.image = [UIImage imageNamed:@"tx_gb"];
  140. _imgView.widthHeight = XY(W(15),W(15));
  141. }
  142. return _imgView;
  143. }
  144. - (UIControl *)control{
  145. if (_control == nil) {
  146. _control = [UIControl new];
  147. _control.tag = 1;
  148. _control.backgroundColor = [UIColor clearColor];
  149. _control.widthHeight = XY(SCREEN_WIDTH,W(0));
  150. }
  151. return _control;
  152. }
  153. #pragma mark 初始化
  154. - (instancetype)initWithFrame:(CGRect)frame{
  155. self = [super initWithFrame:frame];
  156. if (self) {
  157. self.backgroundColor = [UIColor whiteColor];
  158. [self addSubView];
  159. }
  160. return self;
  161. }
  162. //添加subview
  163. - (void)addSubView{
  164. [self addSubview:self.imgView];
  165. [self addSubview:self.control];
  166. [self resetView];
  167. }
  168. #pragma mark 刷新view
  169. - (void)resetView{
  170. [self removeSubViewWithTag:TAG_LINE];//移除线
  171. //刷新view
  172. self.imgView.centerXTop = XY(SCREEN_WIDTH/2,W(15));
  173. self.height = [self addLineFrame:CGRectMake(W(0), self.imgView.bottom+W(15), SCREEN_WIDTH, 1)];
  174. self.control.widthHeight = XY(SCREEN_WIDTH, self.height);
  175. self.control.leftTop = XY(W(0),W(0));
  176. }
  177. @end