// // HomePageNoticFooterView.m // LN_School // // Created by 张嵘 on 2019/7/18. // Copyright © 2019 Danson. All rights reserved. // #import "HomePageNoticFooterView.h" #import "UUMarqueeView.h" @interface HomePageNoticFooterView () @property (nonatomic, readwrite, strong) UIView *contentView; @property (nonatomic, readwrite, strong) UUMarqueeView *contentMarqueeView; @property (nonatomic, readwrite, strong) UILabel *iconLabel; @property (nonatomic, readwrite, strong) UIImageView *iconImageView; @property (nonatomic, readwrite, strong) UIImageView *line; @property (nonatomic, readwrite, strong) UIImageView *footerlineView; @property (nonatomic, readwrite, strong) NSMutableArray *dataSource; @end @implementation HomePageNoticFooterView #pragma mark - Life Cycle - (instancetype)initWithFrame:(CGRect)frame { self = [super initWithFrame:frame]; if (self) { [self addSubview:self.contentView]; [self.contentView addSubview:self.contentMarqueeView]; [self.contentView addSubview:self.iconImageView]; [self.contentView addSubview:self.iconLabel]; [self.contentView addSubview:self.line]; [self.contentView addSubview:self.footerlineView]; [self.contentMarqueeView reloadData]; } return self; } - (void)layoutSubviews { [super layoutSubviews]; [_contentView mas_makeConstraints:^(MASConstraintMaker *make) { make.center.mas_equalTo(self); make.size.mas_equalTo(CGSizeMake(self.bounds.size.width, self.bounds.size.height)); }]; [_iconImageView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_offset(16); make.centerY.mas_equalTo(self.contentView).mas_offset(-5); make.size.mas_equalTo(CGSizeMake(self.bounds.size.height * 0.5 * (163.f / 58.f), self.bounds.size.height * 0.5)); }]; [_iconLabel mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(_iconImageView); make.centerY.mas_equalTo(self.contentView).mas_offset(-5); make.size.mas_equalTo(CGSizeMake(self.bounds.size.height * 0.5 * (163.f / 58.f), self.bounds.size.height * 0.5)); }]; [_contentMarqueeView mas_makeConstraints:^(MASConstraintMaker *make) { make.left.mas_equalTo(_iconImageView.mas_right).mas_offset(16); make.centerY.mas_equalTo(self.contentView).mas_offset(-5); make.size.mas_equalTo(CGSizeMake(self.bounds.size.width - 48 - (self.bounds.size.height * 0.5 * (163.f / 58.f)), self.bounds.size.height)); }]; [_line mas_makeConstraints:^(MASConstraintMaker *make) { make.top.left.right.mas_offset(0); make.height.mas_equalTo(1); }]; [_footerlineView mas_makeConstraints:^(MASConstraintMaker *make) { make.bottom.left.right.mas_offset(0); make.height.mas_equalTo(10); }]; } #pragma mark - UUMarqueeViewDelegate - (NSUInteger)numberOfVisibleItemsForMarqueeView:(UUMarqueeView*)marqueeView { // 指定可视条目的行数,仅[UUMarqueeViewDirectionUpward]时被调用。 // 当[UUMarqueeViewDirectionLeftward]时行数固定为1。 return 1; } - (NSUInteger)numberOfDataForMarqueeView:(UUMarqueeView*)marqueeView { // 指定数据源的个数。例:数据源是字符串数组@[@"A", @"B", @"C"]时,return 3。 return self.dataSource.count; } - (void)createItemView:(UIView*)itemView forMarqueeView:(UUMarqueeView*)marqueeView { // 在marquee view创建时(即'-(void)reloadData'调用后),用于创建条目视图的初始结构,可自行添加任意subview。 // ### 给必要的subview添加tag,可在'-(void)updateItemView:withData:forMarqueeView:'调用时快捷获取并设置内容。 UILabel *content = [[UILabel alloc] initWithFrame:itemView.bounds]; content.font = [UIFont systemFontOfSize:14.0f]; content.textColor = RQTitleTextColor; content.tag = 1001; [itemView addSubview:content]; } - (void)updateItemView:(UIView*)itemView atIndex:(NSUInteger)index forMarqueeView:(UUMarqueeView*)marqueeView { // 设定即将显示的条目内容,在每次marquee view滑动时被调用。 // 'index'即为数据源数组的索引值。 UILabel *content = [itemView viewWithTag:1001]; content.text = self.dataSource[index]; } - (CGFloat)itemViewWidthAtIndex:(NSUInteger)index forMarqueeView:(UUMarqueeView*)marqueeView { // 指定条目在显示数据源内容时的视图宽度,仅[UUMarqueeViewDirectionLeftward]时被调用。 // ### 在数据源不变的情况下,宽度可以仅计算一次并缓存复用。 UILabel *content = [[UILabel alloc] init]; content.font = [UIFont systemFontOfSize:14.0f]; content.text = self.dataSource[index]; return content.intrinsicContentSize.width; } - (void)didTouchItemViewAtIndex:(NSUInteger)index forMarqueeView:(UUMarqueeView*)marqueeView { // 点击事件回调。在'touchEnabled'设置为YES后,触发点击事件时被调用。 NSLog(@"Touch at index %lu", (unsigned long)index); } #pragma mark - LazyLoad -(UIView *)contentView { if (!_contentView) { _contentView = [[UIView alloc] init]; _contentView.backgroundColor = UIColor.whiteColor; } return _contentView; } - (UIImageView *)iconImageView { if (!_iconImageView) { _iconImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"notic"]]; } return _iconImageView; } - (UILabel *)iconLabel { if (!_iconLabel) { _iconLabel = [UILabel new]; _iconLabel.font = [UIFont systemFontOfSize:12]; _iconLabel.textAlignment = NSTextAlignmentCenter; _iconLabel.textColor = UIColor.whiteColor; _iconLabel.text = @"系统公告"; } return _iconLabel; } - (UUMarqueeView *)contentMarqueeView { if (!_contentMarqueeView) { _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]; _contentMarqueeView.delegate = self; _contentMarqueeView.timeIntervalPerScroll = 2.0f; // 条目滑动间隔 _contentMarqueeView.scrollSpeed = 60.0f; // 滑动速度 _contentMarqueeView.itemSpacing = 20.0f; // 左右相邻两个条目的间距,当左侧条目内容的长度超出marquee view整体长度时有效 _contentMarqueeView.touchEnabled = YES; // 设置为YES可监听点击事件,默认值为NO } return _contentMarqueeView; } - (NSMutableArray *)dataSource { if (!_dataSource) { _dataSource = @[@"1月1日起,厦门驾校培训计时将有小!变!化!",@"5月1日起,厦门驾校培训计时将有中!变!化!",@"10月1日起,厦门驾校培训计时将有大!变!化!"].mutableCopy; } return _dataSource; } - (UIImageView *)line { if (!_line) { _line = [[UIImageView alloc] init]; _line.backgroundColor = RQBackGroundColor; } return _line; } - (UIImageView *)footerlineView { if (!_footerlineView) { _footerlineView = [[UIImageView alloc] init]; _footerlineView.backgroundColor = RQBackGroundColor; } return _footerlineView; } @end