自定义滚动条

计算其滑动距离

- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    
    if ([self.collectionView isEqual:scrollView]) {
        
        //计算偏移量
        CGFloat offsetX = self.collectionView.contentOffset.x;
        
        //150----滚动条的总长度
        CGFloat X = offsetX*(150-self.line.frame.size.width)/(self.collectionView.contentSize.width-self.collectionView.frame.size.width);
        [self.line mas_updateConstraints:^(MASConstraintMaker *make) {
            make.left.mas_equalTo(X);
        }];
        
        [self.line.superview layoutIfNeeded];
    }
}

你可能感兴趣的:(自定义滚动条)