123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161 |
- //
- // HPSlideSegmentBackgroundView.m
- // HPSlideSegmentView
- //
- // Created by 何鹏 on 17/6/13.
- // Copyright © 2017年 何鹏. All rights reserved.
- //
- #import "HPSlideSegmentBackgroundView.h"
- #import "HPSlideSegmentLogic.h"
- #import "UIView+HPSlideSegmentRect.h"
- @interface HPSlideSegmentBackgroundView ()<SlideModuleViewDelegate,HPSlideSegmentViewDelegate>
- @property(nonatomic,assign) NSUInteger arrayCount;
- @end
- @implementation HPSlideSegmentBackgroundView
- -(instancetype)initWithFrame:(CGRect)frame
- {
- if (self=[super initWithFrame:frame]) {
- [self updateData];
- [self slideSegmentlayout];
- [self slideAction];
- }
- return self;
- }
- -(void)layoutSubviews{
- [super layoutSubviews];
-
- _slideModuleView.frame=CGRectMake(_slideModuleView.x, _slideModuleView.y, self.width, _slideModuleView.height);
-
- CGFloat y=self.slideModuleView.x+self.slideModuleView.height;
- CGFloat height=self.height-_slideModuleViewHeight;
- _slideSegmenView.frame=CGRectMake(0, y, self.width, height);
- }
- -(void)awakeFromNib
- {
- [super awakeFromNib];
-
- [self updateData];
- [self slideSegmentlayout];
- [self slideAction];
- }
- -(void)updateData
- {
- if ([self.dataSource respondsToSelector:@selector(hp_slideListWithCount)]) {
- self.arrayCount=[self.dataSource hp_slideListWithCount];
- }
-
-
- }
- -(void)updateLayout
- {
- //更新布局
- [self updateData];
- [self slideSegmentlayout];
- }
- -(void)updateLayoutWithIndex:(NSUInteger)index
- {
- [self.slideSegmenView updateLayout:index];
- [self.slideModuleView updateLayoutWithIndex:index];
- }
- -(void)slideSegmentlayout
- {
- [self.slideSegmenView updateScrollerViewWidthWidth:self.arrayCount];
- self.slideModuleView.showCount=self.arrayCount;
-
- [self addSubview:self.slideModuleView];
- [self addSubview:self.slideSegmenView];
-
- }
- -(void)slideAction
- {
- [self.slideModuleView hp_weak:self
- actionButton:^(HPSlideSegmentBackgroundView *weak, NSUInteger buttonIndex) {
-
- [weak.slideSegmenView updateLayout:buttonIndex updateDelegate:NO];
-
- }];
- }
- #pragma mark - HPSlideSegmentViewDataSouce
- -(void)hp_slideWithNowIndex:(NSUInteger)nowIndex readyIndex:(NSUInteger)readyIndex movePercent:(CGFloat)movePercent
- {
- [self.slideModuleView slideWithNowIndex:nowIndex readyIndex:readyIndex movePercent:movePercent];
- }
- #pragma mark - SlideModuleViewDelegate
- -(NSString *)hp_slideContentWithIndex:(NSUInteger)index
- {
- return self.contents[index];
- }
- #pragma mark - 懒加载
- -(void)setSlideModuleViewHeight:(CGFloat)slideModuleViewHeight
- {
-
- if (slideModuleViewHeight<30) {
- slideModuleViewHeight=30;
- }
-
- _slideModuleViewHeight=slideModuleViewHeight;
- _slideModuleView.frame=CGRectMake(0, 0, self.width, slideModuleViewHeight);
- CGFloat y=self.slideModuleView.x+self.slideModuleView.height;
- _slideSegmenView.frame=CGRectMake(0, y, self.width, self.height-y);
- [self updateLayout];
- }
- -(void)setDataSource:(id<HPSlideSegmentBackgroundDataSource>)dataSource
- {
- _dataSource=dataSource;
- [self updateLayout];
- }
- -(void)setContents:(NSArray<NSString *> *)contents
- {
- _contents=contents;
- [self updateLayout];
- }
- -(HPSlideModuleView *)slideModuleView
- {
- if (_slideModuleView==nil) {
- _slideModuleView=[[HPSlideModuleView alloc] initWithFrame:CGRectMake(0, 0, self.width, 30)];
- _slideModuleView.delegate=self;
- }
- return _slideModuleView;
- }
- -(HPSlideSegmentView *)slideSegmenView
- {
- CGFloat y=self.slideModuleView.x+self.slideModuleView.height;
- if (_slideSegmenView==nil) {
- _slideSegmenView=[[HPSlideSegmentView alloc] initWithFrame:CGRectMake(0, y, self.width, self.height)];
- _slideSegmenView.delegate=self;
- }
- return _slideSegmenView;
- }
- @end
|