创建scrollview为底,button的选择状态相连接

。h文件

#import@interface MyButton : UIButton

@property(nonatomic, strong)UIView *view;

//是否显示下划线

-(void)setDownLine:(BOOL)select;

@end

。m文件

#import "MyButton.h"

@implementation MyButton

-(instancetype)initWithFrame:(CGRect)frame

{

self=[super initWithFrame:frame];

if (self) {

CGRect rect = CGRectMake(-3, frame.size.height-6, frame.size.width+10, 2);

self.view = [[UIView alloc] initWithFrame:rect];

self.view.backgroundColor = [UIColor whiteColor];

[self addSubview:self.view];

}

return self;

}

-(void)setDownLine:(BOOL)select

{

if (select==YES) {

self.view.hidden=NO;

}else

{

self.view.hidden=YES;

}

}

scrollview 。h文件

#import@interface MyScrollView : UIScrollView

@property (nonatomic,strong) NSMutableArray *viewArr;

@property (nonatomic,assign) int count;

-(void)setTheScrollView:(int)count;

@end

。m文件

#import "MyScrollView.h"

@implementation MyScrollView

-(instancetype)initWithFrame:(CGRect)frame

{

self=[super initWithFrame:frame];

if (self) {

}

return self;

}

//设置ScrollView包含的view个数

- (void)setTheScrollView:(int)count

{

self.count = count;

self.contentSize = CGSizeMake(ScWidth*count, ScHeight-64-49);

self.pagingEnabled = YES;

self.showsHorizontalScrollIndicator = NO;

self.bounces = NO;

//把view加上

for (int i = 0; i<count;i++)

{

[self addSubview:self.viewArr[i]];

}

}

//创建baseView

- (NSMutableArray *)viewArr

{

if (_viewArr == nil) {

_viewArr = [[NSMutableArray alloc] init];

for (int i = 0; i<self.count;i++)

{

UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(i*ScWidth, 0, ScWidth, ScHeight-64-49)];

[_viewArr addObject:baseView];

}

}

return _viewArr;

}

在根式图。h

- (void)setNavgationTitle:(NSArray *)array;


在子视图控制器中实现


这样就可以关联起来了,效果图


最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容