滚动条的自定义

参考Demo:http://code4app.com/ios/BRScrollBar/51d52c8b6803fad876000000


1、首先在项目中引入BRScrollBarClasses文件夹,并注释掉BarScrollBarController.m中监听frame变化的方法

#pragma mark - observing ContentSize, ContentOffset

- (void)observeValueForKeyPath:(NSString *)keyPath

                      ofObject:(id)object

                        change:(NSDictionary *)change

                       context:(void *)context

{

    if([keyPath isEqualToString:@"contentSize"])

    {

        [self setContentSize];

        

    } else if([keyPath isEqualToString:@"contentOffset"]) {

        [self viewDidScroll];

    }

    else if([keyPath isEqualToString:@"frame"]) {

       // [self scrollViewDidLayoutSubviews];

    }

    

}





2、要自定义UITableView的tableView的滚动条

_brScrollBarControllerCity=[[BRScrollBarController alloc]initForScrollView:tableView inPosition:kIntBRScrollBarPositionRight symbol:1];

重写BrScrollBarController.m中的方法:

- (id) initForScrollView:(UIScrollView *)scrollView inPosition:(BRScrollBarPostions)position symbol:(int)symbol

{

    self = [super init];

    if(self)

    {

        NSLog(@"scrollView.contentSize.height=======%f",scrollView.contentSize.height);

        

        tableContenSizeHeight=scrollView.contentSize.height;

//        signNumber用于标志显示的是哪个级联列表

        signNumber=symbol;

        _scrollView = scrollView;

        _scrollView.showsVerticalScrollIndicator = NO;

        [self addObservers];

        [self initScrollBarViewForPostion:position symbol:symbol];


    }

    return self;

}


- (void)initScrollBarViewForPostion:(BRScrollBarPostions)position symbol:(int)symbol

{

    CGPoint origin = [self scrollBarOriginForPosition:position];

    BRScrollBarView *scrollBar=nil;

    if (symbol==1) {

        

         scrollBar= [[BRScrollBarView alloc] initWithFrame:CGRectMake(origin.x, origin.y,

                                                                                       kIntBRScrollBarWidth,

                                                                      self.scrollView.frame.size.height) tableContentSizeHeight:tableContenSizeHeight];

      


        

    }else if (symbol==2){

        

        NSLog(@"self.scrollView.frame.size.height=====%f",self.scrollView.frame.size.height);

        

        scrollBar= [[BRScrollBarView alloc] initWithFrame:CGRectMake(312.0,

                                                                     origin.y,

                                                                     kIntBRScrollBarWidth,

                                                                     self.scrollView.frame.size.height) tableContentSizeHeight:tableContenSizeHeight];


    

    }else if(symbol==3){

        scrollBar= [[BRScrollBarView alloc] initWithFrame:CGRectMake(312,

                                                                     origin.y,

                                                                     kIntBRScrollBarWidth,

                                                                     self.scrollView.frame.size.height) tableContentSizeHeight:tableContenSizeHeight];


    

    }else if(symbol==4){

        scrollBar= [[BRScrollBarView alloc] initWithFrame:CGRectMake(205,

                                                                     origin.y,

                                                                     kIntBRScrollBarWidth,

                                                                     self.scrollView.frame.size.height) tableContentSizeHeight:tableContenSizeHeight];


        

    }

    scrollBar.autoresizingMask = [self autoResizingMaskForPosition:position];

    scrollBar.delegate = self;

    [self.scrollView.superview addSubview:scrollBar];

    

    _scrollBar = scrollBar;

    

}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值