Files
yinmeng-ios/xplan-ios/Main/Home/View/XPPartyHeaderView.m

118 lines
3.3 KiB
Mathematica
Raw Normal View History

2023-03-07 18:51:04 +08:00
//
// XPPartyHeaderView.m
// xplan-ios
//
// Created by XY on 2023/3/7.
//
#import "XPPartyHeaderView.h"
///Third
#import <Masonry.h>
#import <SDCycleScrollView/SDCycleScrollView.h>
/// Tool
#import "ThemeColor.h"
#import "XPMacro.h"
#import "NSArray+Safe.h"
2023-03-08 19:28:33 +08:00
@interface XPPartyHeaderView()<SDCycleScrollViewDelegate>
2023-03-07 18:51:04 +08:00
///
@property (nonatomic, strong) UIView *bgView;
///
@property (nonatomic, strong) SDCycleScrollView *cycleScrollView;
@end
@implementation XPPartyHeaderView
- (instancetype)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
[self initSubViews];
[self initSubViewConstraints];
}
return self;
}
+ (CGFloat)getPartyHeaderViewHeight {
CGFloat width = KScreenWidth-15*2;
CGFloat height = 74.0/345.0*width;
return height+20;
}
#pragma mark - Private Method
- (void)initSubViews {
[self addSubview:self.bgView];
[self.bgView addSubview:self.cycleScrollView];
}
- (void)initSubViewConstraints {
[self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.mas_equalTo(10);
make.left.mas_equalTo(15);
make.right.mas_equalTo(-15);
make.bottom.mas_equalTo(-10);
}];
[self.cycleScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.left.right.bottom.mas_equalTo(0);
}];
}
+ (CGFloat)getTopicHeaderViewHeight {
CGFloat width = KScreenWidth-15*2;
CGFloat height = 74.0/345.0*width;
return height+20;
}
#pragma mark - SDCycleScrollViewDelegate
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didSelectItemAtIndex:(NSInteger)index {
HomeBannerInfoModel * bannerInfo = [self.bannerList safeObjectAtIndex1:index];
if (self.delegate && [self.delegate respondsToSelector:@selector(partyHeaderViewClickBanner:)]) {
[self.delegate partyHeaderViewClickBanner:bannerInfo];
}
}
#pragma mark - Getters And Setters
- (void)setBannerList:(NSArray<HomeBannerInfoModel *> *)bannerList {
_bannerList = bannerList;
if (_bannerList.count > 0) {
NSMutableArray * array = [NSMutableArray array];
[_bannerList enumerateObjectsUsingBlock:^(HomeBannerInfoModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
if (obj.bannerPic.length > 0) {
[array addObject:obj.bannerPic];
}
}];
if (array.count > 0) {
self.cycleScrollView.imageURLStringsGroup = array;
[self.cycleScrollView autoScroll];
}
}
}
- (UIView *)bgView {
if (!_bgView) {
_bgView = [[UIView alloc] init];
_bgView.backgroundColor = [ThemeColor appCellBackgroundColor];
_bgView.layer.cornerRadius = 12;
_bgView.clipsToBounds = YES;
}
return _bgView;
}
- (SDCycleScrollView *)cycleScrollView {
if (!_cycleScrollView) {
_cycleScrollView = [[SDCycleScrollView alloc] init];
_cycleScrollView.backgroundColor = [UIColor clearColor];
_cycleScrollView.layer.cornerRadius = 10;
_cycleScrollView.layer.masksToBounds = YES;
2023-03-15 19:51:07 +08:00
_cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
2023-03-07 18:51:04 +08:00
_cycleScrollView.delegate = self;
_cycleScrollView.showPageControl = NO;
_cycleScrollView.autoScrollTimeInterval = 5.0;
_cycleScrollView.tag = 9999;
}
return _cycleScrollView;
}
@end