参考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;
}