。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 { [self addSubview:self.viewArr[i]]; } } //创建baseView - (NSMutableArray *)viewArr { if (_viewArr == nil) { _viewArr = [[NSMutableArray alloc] init]; for (int i = 0; i { UIView *baseView = [[UIView alloc] initWithFrame:CGRectMake(i*ScWidth, 0, ScWidth, ScHeight-64-49)]; [_viewArr addObject:baseView]; } } return _viewArr; } 在根式图。h - (void)setNavgationTitle:(NSArray *)array; 这样就可以关联起来了,效果图