HomePageNoticFooterView.m 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. //
  2. // HomePageNoticFooterView.m
  3. // LN_School
  4. //
  5. // Created by 张嵘 on 2019/7/18.
  6. // Copyright © 2019 Danson. All rights reserved.
  7. //
  8. #import "HomePageNoticFooterView.h"
  9. #import "UUMarqueeView.h"
  10. @interface HomePageNoticFooterView () <UUMarqueeViewDelegate>
  11. @property (nonatomic, readwrite, strong) UIView *contentView;
  12. @property (nonatomic, readwrite, strong) UUMarqueeView *contentMarqueeView;
  13. @property (nonatomic, readwrite, strong) UILabel *iconLabel;
  14. @property (nonatomic, readwrite, strong) UIImageView *iconImageView;
  15. @property (nonatomic, readwrite, strong) UIImageView *line;
  16. @property (nonatomic, readwrite, strong) UIImageView *footerlineView;
  17. @property (nonatomic, readwrite, strong) NSMutableArray *dataSource;
  18. @end
  19. @implementation HomePageNoticFooterView
  20. #pragma mark - Life Cycle
  21. - (instancetype)initWithFrame:(CGRect)frame {
  22. self = [super initWithFrame:frame];
  23. if (self) {
  24. [self addSubview:self.contentView];
  25. [self.contentView addSubview:self.contentMarqueeView];
  26. [self.contentView addSubview:self.iconImageView];
  27. [self.contentView addSubview:self.iconLabel];
  28. [self.contentView addSubview:self.line];
  29. [self.contentView addSubview:self.footerlineView];
  30. [self.contentMarqueeView reloadData];
  31. }
  32. return self;
  33. }
  34. - (void)layoutSubviews {
  35. [super layoutSubviews];
  36. [_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
  37. make.center.mas_equalTo(self);
  38. make.size.mas_equalTo(CGSizeMake(self.bounds.size.width, self.bounds.size.height));
  39. }];
  40. [_iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
  41. make.left.mas_offset(16);
  42. make.centerY.mas_equalTo(self.contentView).mas_offset(-5);
  43. make.size.mas_equalTo(CGSizeMake(self.bounds.size.height * 0.5 * (163.f / 58.f), self.bounds.size.height * 0.5));
  44. }];
  45. [_iconLabel mas_makeConstraints:^(MASConstraintMaker *make) {
  46. make.left.mas_equalTo(_iconImageView);
  47. make.centerY.mas_equalTo(self.contentView).mas_offset(-5);
  48. make.size.mas_equalTo(CGSizeMake(self.bounds.size.height * 0.5 * (163.f / 58.f), self.bounds.size.height * 0.5));
  49. }];
  50. [_contentMarqueeView mas_makeConstraints:^(MASConstraintMaker *make) {
  51. make.left.mas_equalTo(_iconImageView.mas_right).mas_offset(16);
  52. make.centerY.mas_equalTo(self.contentView).mas_offset(-5);
  53. make.size.mas_equalTo(CGSizeMake(self.bounds.size.width - 48 - (self.bounds.size.height * 0.5 * (163.f / 58.f)), self.bounds.size.height));
  54. }];
  55. [_line mas_makeConstraints:^(MASConstraintMaker *make) {
  56. make.top.left.right.mas_offset(0);
  57. make.height.mas_equalTo(1);
  58. }];
  59. [_footerlineView mas_makeConstraints:^(MASConstraintMaker *make) {
  60. make.bottom.left.right.mas_offset(0);
  61. make.height.mas_equalTo(10);
  62. }];
  63. }
  64. #pragma mark - UUMarqueeViewDelegate
  65. - (NSUInteger)numberOfVisibleItemsForMarqueeView:(UUMarqueeView*)marqueeView {
  66. // 指定可视条目的行数,仅[UUMarqueeViewDirectionUpward]时被调用。
  67. // 当[UUMarqueeViewDirectionLeftward]时行数固定为1。
  68. return 1;
  69. }
  70. - (NSUInteger)numberOfDataForMarqueeView:(UUMarqueeView*)marqueeView {
  71. // 指定数据源的个数。例:数据源是字符串数组@[@"A", @"B", @"C"]时,return 3。
  72. return self.dataSource.count;
  73. }
  74. - (void)createItemView:(UIView*)itemView forMarqueeView:(UUMarqueeView*)marqueeView {
  75. // 在marquee view创建时(即'-(void)reloadData'调用后),用于创建条目视图的初始结构,可自行添加任意subview。
  76. // ### 给必要的subview添加tag,可在'-(void)updateItemView:withData:forMarqueeView:'调用时快捷获取并设置内容。
  77. UILabel *content = [[UILabel alloc] initWithFrame:itemView.bounds];
  78. content.font = [UIFont systemFontOfSize:14.0f];
  79. content.textColor = RQTitleTextColor;
  80. content.tag = 1001;
  81. [itemView addSubview:content];
  82. }
  83. - (void)updateItemView:(UIView*)itemView atIndex:(NSUInteger)index forMarqueeView:(UUMarqueeView*)marqueeView {
  84. // 设定即将显示的条目内容,在每次marquee view滑动时被调用。
  85. // 'index'即为数据源数组的索引值。
  86. UILabel *content = [itemView viewWithTag:1001];
  87. content.text = self.dataSource[index];
  88. }
  89. - (CGFloat)itemViewWidthAtIndex:(NSUInteger)index forMarqueeView:(UUMarqueeView*)marqueeView {
  90. // 指定条目在显示数据源内容时的视图宽度,仅[UUMarqueeViewDirectionLeftward]时被调用。
  91. // ### 在数据源不变的情况下,宽度可以仅计算一次并缓存复用。
  92. UILabel *content = [[UILabel alloc] init];
  93. content.font = [UIFont systemFontOfSize:14.0f];
  94. content.text = self.dataSource[index];
  95. return content.intrinsicContentSize.width;
  96. }
  97. - (void)didTouchItemViewAtIndex:(NSUInteger)index forMarqueeView:(UUMarqueeView*)marqueeView {
  98. // 点击事件回调。在'touchEnabled'设置为YES后,触发点击事件时被调用。
  99. NSLog(@"Touch at index %lu", (unsigned long)index);
  100. }
  101. #pragma mark - LazyLoad
  102. -(UIView *)contentView {
  103. if (!_contentView) {
  104. _contentView = [[UIView alloc] init];
  105. _contentView.backgroundColor = UIColor.whiteColor;
  106. }
  107. return _contentView;
  108. }
  109. - (UIImageView *)iconImageView {
  110. if (!_iconImageView) {
  111. _iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"notic"]];
  112. }
  113. return _iconImageView;
  114. }
  115. - (UILabel *)iconLabel {
  116. if (!_iconLabel) {
  117. _iconLabel = [UILabel new];
  118. _iconLabel.font = [UIFont systemFontOfSize:12];
  119. _iconLabel.textAlignment = NSTextAlignmentCenter;
  120. _iconLabel.textColor = UIColor.whiteColor;
  121. _iconLabel.text = @"系统公告";
  122. }
  123. return _iconLabel;
  124. }
  125. - (UUMarqueeView *)contentMarqueeView {
  126. if (!_contentMarqueeView) {
  127. _contentMarqueeView = [[UUMarqueeView alloc] initWithFrame:CGRectMake(0, 0, self.bounds.size.width - 32 - (self.bounds.size.height * 0.5 * (163.f / 58.f)), self.bounds.size.height) direction:UUMarqueeViewDirectionLeftward];
  128. _contentMarqueeView.delegate = self;
  129. _contentMarqueeView.timeIntervalPerScroll = 2.0f; // 条目滑动间隔
  130. _contentMarqueeView.scrollSpeed = 60.0f; // 滑动速度
  131. _contentMarqueeView.itemSpacing = 20.0f; // 左右相邻两个条目的间距,当左侧条目内容的长度超出marquee view整体长度时有效
  132. _contentMarqueeView.touchEnabled = YES; // 设置为YES可监听点击事件,默认值为NO
  133. }
  134. return _contentMarqueeView;
  135. }
  136. - (NSMutableArray *)dataSource {
  137. if (!_dataSource) {
  138. _dataSource = @[@"1月1日起,厦门驾校培训计时将有小!变!化!",@"5月1日起,厦门驾校培训计时将有中!变!化!",@"10月1日起,厦门驾校培训计时将有大!变!化!"].mutableCopy;
  139. }
  140. return _dataSource;
  141. }
  142. - (UIImageView *)line {
  143. if (!_line) {
  144. _line = [[UIImageView alloc] init];
  145. _line.backgroundColor = RQBackGroundColor;
  146. }
  147. return _line;
  148. }
  149. - (UIImageView *)footerlineView {
  150. if (!_footerlineView) {
  151. _footerlineView = [[UIImageView alloc] init];
  152. _footerlineView.backgroundColor = RQBackGroundColor;
  153. }
  154. return _footerlineView;
  155. }
  156. @end