// // XPPartyHeaderView.m // xplan-ios // // Created by XY on 2023/3/7. // #import "XPPartyHeaderView.h" ///Third #import #import /// Tool #import "ThemeColor.h" #import "XPMacro.h" #import "NSArray+Safe.h" @interface XPPartyHeaderView() /// 背景 @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 *)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; _cycleScrollView.bannerImageViewContentMode = UIViewContentModeScaleAspectFill; _cycleScrollView.delegate = self; _cycleScrollView.showPageControl = NO; _cycleScrollView.autoScrollTimeInterval = 5.0; _cycleScrollView.tag = 9999; } return _cycleScrollView; } @end