美文网首页
创建scrollview为底,button的选择状态相连接

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

作者: 尘世中迷途码农 | 来源:发表于2016-05-30 23:50 被阅读89次

    。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;

    在子视图控制器中实现

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


    相关文章

      网友评论

          本文标题:创建scrollview为底,button的选择状态相连接

          本文链接:https://www.haomeiwen.com/subject/anscdttx.html